Fix warnings
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
// Copyright (C) 2012 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2012-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "GameLib.h"
|
#include "GameLib.h"
|
||||||
extern int gamelib_debug;
|
|
||||||
|
|
||||||
#include "GameEnts.h"
|
#include "GameEnts.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2012 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2012-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _GAMEENTS_H_
|
#ifndef GameEnts_H
|
||||||
#define _GAMEENTS_H_
|
#define GameEnts_H
|
||||||
|
|
||||||
#define Ent_Player 1
|
#define Ent_Player 1
|
||||||
#define Ent_Platform 2
|
#define Ent_Platform 2
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2012 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2012-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Copyright (C) 2012 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2012-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
#ifndef _GAMEMAP_H_
|
#ifndef GameMap_H
|
||||||
#define _GAMEMAP_H_
|
#define GameMap_H
|
||||||
|
|
||||||
int GameMap_LoadLevel(char *filename, int res);
|
int GameMap_LoadLevel(char *filename, int res);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2012 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2012-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "GameLib.h"
|
#include "GameLib.h"
|
||||||
extern int gamelib_debug;
|
|
||||||
|
|
||||||
#include "GameEnts.h"
|
#include "GameEnts.h"
|
||||||
#include "GameMap.h"
|
#include "GameMap.h"
|
||||||
@@ -32,13 +31,6 @@ void DrawGame(float f) { MainGame_Text(8, 8, "Hello world!"); }
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|||||||
27
src/Anim.c
27
src/Anim.c
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -12,23 +12,23 @@
|
|||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
DrawImg img;
|
DrawImg img;
|
||||||
int w;
|
int32_t w;
|
||||||
float fps;
|
float fps;
|
||||||
int frames;
|
int32_t frames;
|
||||||
int ftime;
|
int32_t frameTime;
|
||||||
int time;
|
int32_t time;
|
||||||
} Animation;
|
} Animation;
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Anim_LoadAnim
|
// Anim_LoadAnim
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
Anim Anim_LoadAnim(char *fichero, int width, int frames, float fps) {
|
Anim Anim_LoadAnim(char *filename, int width, int frames, float fps) {
|
||||||
DrawImg img;
|
DrawImg img;
|
||||||
Animation *anim;
|
Animation *anim;
|
||||||
int w, h;
|
int w, h;
|
||||||
|
|
||||||
img = Draw_LoadImage(fichero);
|
img = Draw_LoadImage(filename);
|
||||||
if (!img) {
|
if (!img) {
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@@ -44,8 +44,8 @@ Anim Anim_LoadAnim(char *fichero, int width, int frames, float fps) {
|
|||||||
}
|
}
|
||||||
anim->fps = fps;
|
anim->fps = fps;
|
||||||
anim->frames = frames;
|
anim->frames = frames;
|
||||||
anim->ftime = 1000 / fps;
|
anim->frameTime = (int)(1000.0f / fps);
|
||||||
anim->time = anim->ftime * frames;
|
anim->time = anim->frameTime * frames;
|
||||||
|
|
||||||
return ((Anim)anim);
|
return ((Anim)anim);
|
||||||
}
|
}
|
||||||
@@ -66,10 +66,10 @@ int Anim_GetTime(Anim a) {
|
|||||||
// Gets the animation size.
|
// Gets the animation size.
|
||||||
void Anim_GetSize(Anim a, int *w, int *h) {
|
void Anim_GetSize(Anim a, int *w, int *h) {
|
||||||
Animation *anim = a;
|
Animation *anim = a;
|
||||||
int waux;
|
int widthAux;
|
||||||
|
|
||||||
*w = anim->w;
|
*w = anim->w;
|
||||||
Draw_GetSize(anim->img, &waux, h);
|
Draw_GetSize(anim->img, &widthAux, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -112,7 +112,7 @@ void Anim_Draw(Anim a, int time_ms, int x, int y, float scale[2]) {
|
|||||||
Animation *anim = a;
|
Animation *anim = a;
|
||||||
int frame;
|
int frame;
|
||||||
|
|
||||||
frame = (time_ms / anim->ftime) % anim->frames;
|
frame = (time_ms / anim->frameTime) % anim->frames;
|
||||||
Draw_DrawImgPartHoriz(anim->img, x, y, anim->w, frame, scale);
|
Draw_DrawImgPartHoriz(anim->img, x, y, anim->w, frame, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +214,8 @@ void AnimPlay_GetSize(AnimPlay *ani, int *w, int *h) {
|
|||||||
if (ani->anim) {
|
if (ani->anim) {
|
||||||
Anim_GetSize(ani->anim, w, h);
|
Anim_GetSize(ani->anim, w, h);
|
||||||
return;
|
return;
|
||||||
} else if (ani->img) {
|
}
|
||||||
|
if (ani->img) {
|
||||||
Draw_GetSize(ani->img, w, h);
|
Draw_GetSize(ani->img, w, h);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _ANIM_H_
|
#ifndef Amin_H
|
||||||
#define _ANIM_H_
|
#define Amin_H
|
||||||
|
|
||||||
#include "Draw.h"
|
#include "Draw.h"
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ typedef void *Anim;
|
|||||||
// Anim_LoadAnim
|
// Anim_LoadAnim
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
Anim Anim_LoadAnim(char *fichero, int width, int frames, float fps);
|
Anim Anim_LoadAnim(char *filename, int width, int frames, float fps);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Anim_GetTime
|
// Anim_GetTime
|
||||||
|
|||||||
135
src/Audio.c
135
src/Audio.c
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define _WIN32_WINNT 0x0501
|
#define _WIN32_WINNT 0x0501
|
||||||
@@ -21,16 +21,16 @@ static void Audio_MixerCallback(void *ud, Uint8 *stream, int l);
|
|||||||
// Reference to a sound.
|
// Reference to a sound.
|
||||||
typedef struct TAudioWave TAudioWave, *AudioWave;
|
typedef struct TAudioWave TAudioWave, *AudioWave;
|
||||||
struct TAudioWave {
|
struct TAudioWave {
|
||||||
unsigned int sampleRate;
|
uint32_t sampleRate;
|
||||||
int channels;
|
int32_t channels;
|
||||||
int bpb;
|
int32_t bpb;
|
||||||
int BPB;
|
int32_t BPB;
|
||||||
Uint32 len;
|
int32_t len;
|
||||||
Uint8 *buffer;
|
uint8_t *buffer;
|
||||||
|
|
||||||
AudioWave next;
|
AudioWave next;
|
||||||
};
|
};
|
||||||
AudioWave _waves = NULL;
|
AudioWave g_Waves = NULL;
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// AudioChan //
|
// AudioChan //
|
||||||
@@ -39,18 +39,18 @@ AudioWave _waves = NULL;
|
|||||||
typedef struct TAudioChan TAudioChan, *AudioChan;
|
typedef struct TAudioChan TAudioChan, *AudioChan;
|
||||||
struct TAudioChan {
|
struct TAudioChan {
|
||||||
AudioWave wave;
|
AudioWave wave;
|
||||||
Uint32 pos;
|
int32_t pos;
|
||||||
unsigned char rightvol;
|
uint8_t rightVolume;
|
||||||
unsigned char leftvol;
|
uint8_t leftVolume;
|
||||||
|
|
||||||
int loop;
|
int32_t loop;
|
||||||
|
|
||||||
AudioChan next;
|
AudioChan next;
|
||||||
};
|
};
|
||||||
AudioChan _channels = NULL;
|
AudioChan g_Channels = NULL;
|
||||||
AudioChan _free_channels = NULL;
|
AudioChan g_FreeChannels = NULL;
|
||||||
|
|
||||||
static SDL_AudioDeviceID _audioDeviceID = 0;
|
static SDL_AudioDeviceID g_AudioDeviceID = 0;
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Audio_Init
|
// Audio_Init
|
||||||
@@ -60,10 +60,9 @@ int Audio_Init() {
|
|||||||
SDL_AudioSpec as;
|
SDL_AudioSpec as;
|
||||||
SDL_AudioSpec as2;
|
SDL_AudioSpec as2;
|
||||||
|
|
||||||
// Initialize audio subsistem
|
// Initialize audio subsystem
|
||||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
|
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
|
||||||
Print("Audio_Init: Failure initializing SDL Audio.\n");
|
Print("ERROR: Audio_Init: Failure initializing SDL Audio. %s\n", SDL_GetError());
|
||||||
Print("\tSDL Error: %s\n", SDL_GetError());
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,22 +72,21 @@ int Audio_Init() {
|
|||||||
as.channels = 2;
|
as.channels = 2;
|
||||||
as.samples = 2048;
|
as.samples = 2048;
|
||||||
as.callback = Audio_MixerCallback;
|
as.callback = Audio_MixerCallback;
|
||||||
_audioDeviceID = SDL_OpenAudioDevice(NULL, 0, &as, &as2, 0);
|
g_AudioDeviceID = SDL_OpenAudioDevice(NULL, 0, &as, &as2, 0);
|
||||||
if (_audioDeviceID == 0) {
|
if (g_AudioDeviceID == 0) {
|
||||||
Print("Audio_Init: Failure opening audio.\n");
|
Print("ERROR: Audio_Init: Failure opening audio. %s\n", SDL_GetError());
|
||||||
Print("\tSDL Error: %s\n", SDL_GetError());
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asert results
|
// 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");
|
Print("ERROR: Audio_Init: Failure opening audio. (44.1Khz/16b/2c).\n");
|
||||||
SDL_CloseAudio();
|
SDL_CloseAudio();
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unpause and ready to go
|
// Unpause and ready to go
|
||||||
SDL_PauseAudioDevice(_audioDeviceID, 0);
|
SDL_PauseAudioDevice(g_AudioDeviceID, 0);
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -97,13 +95,13 @@ int Audio_Init() {
|
|||||||
// Audio_MixerCallback
|
// Audio_MixerCallback
|
||||||
//
|
//
|
||||||
// Mixes the audio channels.
|
// Mixes the audio channels.
|
||||||
static void Audio_MixerCallback(void *ud, Uint8 *stream, int l) {
|
static void Audio_MixerCallback(void *ud, uint8_t *stream, int l) {
|
||||||
signed short *ptr_out, *ptr_wave;
|
int16_t *ptr_out, *ptr_wave;
|
||||||
AudioChan prevchan;
|
AudioChan previousChannel;
|
||||||
AudioChan chan;
|
AudioChan chan;
|
||||||
AudioWave wave;
|
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 channelRemaining;
|
||||||
int len_mix;
|
int len_mix;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -111,19 +109,19 @@ static void Audio_MixerCallback(void *ud, Uint8 *stream, int l) {
|
|||||||
memset(stream, 0, l);
|
memset(stream, 0, l);
|
||||||
|
|
||||||
// Mix all the channels
|
// Mix all the channels
|
||||||
prevchan = NULL;
|
previousChannel = NULL;
|
||||||
chan = _channels;
|
chan = g_Channels;
|
||||||
while (chan) {
|
while (chan) {
|
||||||
if (!chan->wave) {
|
if (!chan->wave) {
|
||||||
// Remove finished channels
|
// Remove finished channels
|
||||||
AudioChan aux_chan = chan->next;
|
AudioChan aux_chan = chan->next;
|
||||||
chan->next = _free_channels;
|
chan->next = g_FreeChannels;
|
||||||
_free_channels = chan;
|
g_FreeChannels = chan;
|
||||||
chan = aux_chan;
|
chan = aux_chan;
|
||||||
if (prevchan) {
|
if (previousChannel) {
|
||||||
prevchan->next = chan;
|
previousChannel->next = chan;
|
||||||
} else {
|
} else {
|
||||||
_channels = chan;
|
g_Channels = chan;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -133,15 +131,15 @@ static void Audio_MixerCallback(void *ud, Uint8 *stream, int l) {
|
|||||||
ptr_wave = ((signed short *)chan->wave->buffer) + chan->pos;
|
ptr_wave = ((signed short *)chan->wave->buffer) + chan->pos;
|
||||||
wave = chan->wave;
|
wave = chan->wave;
|
||||||
|
|
||||||
// Determine mixing lenght
|
// Determine mixing length
|
||||||
chan_remain = wave->len - chan->pos;
|
channelRemaining = wave->len - chan->pos;
|
||||||
if (chan_remain > len) {
|
if (channelRemaining > len) {
|
||||||
len_mix = len;
|
len_mix = len;
|
||||||
} else {
|
} else {
|
||||||
if (chan->loop) {
|
if (chan->loop) {
|
||||||
len_mix = len;
|
len_mix = len;
|
||||||
} else {
|
} else {
|
||||||
len_mix = chan_remain;
|
len_mix = channelRemaining;
|
||||||
}
|
}
|
||||||
chan->wave = NULL;
|
chan->wave = NULL;
|
||||||
}
|
}
|
||||||
@@ -152,24 +150,24 @@ static void Audio_MixerCallback(void *ud, Uint8 *stream, int l) {
|
|||||||
|
|
||||||
// Left Channel
|
// Left Channel
|
||||||
temp = ptr_out[0];
|
temp = ptr_out[0];
|
||||||
temp += (ptr_wave[0] * chan->leftvol) >> 8;
|
temp += (ptr_wave[0] * chan->leftVolume) >> 8;
|
||||||
if (temp > (1 << 14)) {
|
if (temp > (1 << 14)) {
|
||||||
ptr_out[0] = 1 << 14;
|
ptr_out[0] = 1 << 14;
|
||||||
} else if (temp < -(1 << 14)) {
|
} else if (temp < -(1 << 14)) {
|
||||||
ptr_out[0] = -(1 << 14);
|
ptr_out[0] = -(1 << 14);
|
||||||
} else {
|
} else {
|
||||||
ptr_out[0] = temp;
|
ptr_out[0] = (int16_t)temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right Channel
|
// Right Channel
|
||||||
temp = ptr_out[1];
|
temp = ptr_out[1];
|
||||||
temp += (ptr_wave[0] * chan->rightvol) >> 8;
|
temp += (ptr_wave[0] * chan->rightVolume) >> 8;
|
||||||
if (temp > (1 << 14)) {
|
if (temp > (1 << 14)) {
|
||||||
ptr_out[1] = 1 << 14;
|
ptr_out[1] = 1 << 14;
|
||||||
} else if (temp < -(1 << 14)) {
|
} else if (temp < -(1 << 14)) {
|
||||||
ptr_out[1] = -(1 << 14);
|
ptr_out[1] = -(1 << 14);
|
||||||
} else {
|
} else {
|
||||||
ptr_out[1] = temp;
|
ptr_out[1] = (int16_t)temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next sample
|
// Next sample
|
||||||
@@ -190,7 +188,7 @@ static void Audio_MixerCallback(void *ud, Uint8 *stream, int l) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Next channel
|
// Next channel
|
||||||
prevchan = chan;
|
previousChannel = chan;
|
||||||
chan = chan->next;
|
chan = chan->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,14 +211,14 @@ AudioSnd Audio_LoadSound(char *filename) {
|
|||||||
|
|
||||||
f = fopen(filename, "rb");
|
f = fopen(filename, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
Print("Audio_LoadSound: Failure opening file.\n");
|
Print("ERROR: Audio_LoadSound: Failure opening file. \"%s\".\n", filename);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read id "RIFF"
|
// Read id "RIFF"
|
||||||
fread(id, 4, sizeof(char), f);
|
fread(id, 4, sizeof(char), f);
|
||||||
if (strcmp(id, "RIFF")) {
|
if (strcmp(id, "RIFF") != 0) {
|
||||||
Print("Audio_LoadSound: File is not RIFF.\n");
|
Print("ERROR: Audio_LoadSound: File is not RIFF. \"%s\".\n", filename);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@@ -230,8 +228,8 @@ AudioSnd Audio_LoadSound(char *filename) {
|
|||||||
|
|
||||||
// Read id "WAVE"
|
// Read id "WAVE"
|
||||||
fread(id, 4, sizeof(char), f);
|
fread(id, 4, sizeof(char), f);
|
||||||
if (strcmp(id, "WAVE")) {
|
if (strcmp(id, "WAVE") != 0) {
|
||||||
Print("Audio_LoadSound: File is not WAVE.\n");
|
Print("ERROR:Audio_LoadSound: File is not WAVE. \"%s\".\n", filename);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@@ -240,13 +238,13 @@ AudioSnd Audio_LoadSound(char *filename) {
|
|||||||
fread(id, 1, sizeof(char) * 4, f); // Read "fmt "
|
fread(id, 1, sizeof(char) * 4, f); // Read "fmt "
|
||||||
fread(&formatLen, 1, sizeof(int), f);
|
fread(&formatLen, 1, sizeof(int), f);
|
||||||
if (formatLen < 14) {
|
if (formatLen < 14) {
|
||||||
Print("Audio_LoadSound: File too short.\n");
|
Print("ERROR: Audio_LoadSound: File too short. \"%s\".\n", filename);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
fread(&formatTag, 1, sizeof(short), f); // 1=PCM
|
fread(&formatTag, 1, sizeof(short), f); // 1=PCM
|
||||||
if (formatTag != 1) {
|
if (formatTag != 1) {
|
||||||
Print("Audio_LoadSound: Not PCM format.\n");
|
Print("ERROR: Audio_LoadSound: Not PCM format. \"%s\".\n", filename);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@@ -260,30 +258,31 @@ AudioSnd Audio_LoadSound(char *filename) {
|
|||||||
// Assert sound format
|
// Assert sound format
|
||||||
if (sampleRate != 44100 || channels != 1 || bitsPerSample != 2) {
|
if (sampleRate != 44100 || channels != 1 || bitsPerSample != 2) {
|
||||||
Print(
|
Print(
|
||||||
"Audio_LoadSound: Format not supported: "
|
"ERROR: Audio_LoadSound: Format not supported: "
|
||||||
"sampleRate:%d; channels:%d; BPB:%d\n",
|
"sampleRate:%d; channels:%d; BPB:%d. \"%s\"\n",
|
||||||
sampleRate,
|
sampleRate,
|
||||||
channels,
|
channels,
|
||||||
bitsPerSample);
|
bitsPerSample,
|
||||||
|
filename);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip no "data" blocks
|
// Skip no "data" blocks
|
||||||
do {
|
do {
|
||||||
int lenRead = fread(id, 1, sizeof(char) * 4, f);
|
size_t lenRead = fread(id, 1, sizeof(char) * 4, f);
|
||||||
if (lenRead < 4) {
|
if (lenRead < 4) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "data")) {
|
if (strcmp(id, "data") != 0) {
|
||||||
fread(&dataSize, 1, sizeof(int), f);
|
fread(&dataSize, 1, sizeof(int), f);
|
||||||
fseek(f, dataSize, SEEK_CUR);
|
fseek(f, dataSize, SEEK_CUR);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (1);
|
} while (1);
|
||||||
if (strcmp(id, "data")) {
|
if (strcmp(id, "data") != 0) {
|
||||||
Print("Audio_LoadSound: DATA block not found\n");
|
Print("ERROR: Audio_LoadSound: DATA block not found. \"%s\".\n", filename);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@@ -305,8 +304,8 @@ AudioSnd Audio_LoadSound(char *filename) {
|
|||||||
wave->len = dataSize / (wave->BPB * wave->channels);
|
wave->len = dataSize / (wave->BPB * wave->channels);
|
||||||
|
|
||||||
// Take a reference
|
// Take a reference
|
||||||
wave->next = _waves;
|
wave->next = g_Waves;
|
||||||
_waves = wave;
|
g_Waves = wave;
|
||||||
|
|
||||||
return (wave);
|
return (wave);
|
||||||
}
|
}
|
||||||
@@ -315,7 +314,7 @@ AudioSnd Audio_LoadSound(char *filename) {
|
|||||||
// Audio_PlaySound
|
// Audio_PlaySound
|
||||||
//
|
//
|
||||||
// Loads a sound, giving a reference.
|
// Loads a sound, giving a reference.
|
||||||
AudioChn Audio_PlaySound(AudioSnd snd, float leftvol, float rightvol, int loop) {
|
AudioChn Audio_PlaySound(AudioSnd snd, float leftVolume, float rightVolume, int loop) {
|
||||||
AudioChan chan;
|
AudioChan chan;
|
||||||
AudioWave wave;
|
AudioWave wave;
|
||||||
if (!snd) {
|
if (!snd) {
|
||||||
@@ -326,9 +325,9 @@ AudioChn Audio_PlaySound(AudioSnd snd, float leftvol, float rightvol, int loop)
|
|||||||
wave = snd;
|
wave = snd;
|
||||||
|
|
||||||
// Get a free channel
|
// Get a free channel
|
||||||
if (_free_channels) {
|
if (g_FreeChannels) {
|
||||||
chan = _free_channels;
|
chan = g_FreeChannels;
|
||||||
_free_channels = chan->next;
|
g_FreeChannels = chan->next;
|
||||||
chan->next = NULL;
|
chan->next = NULL;
|
||||||
} else {
|
} else {
|
||||||
chan = malloc(sizeof(TAudioChan));
|
chan = malloc(sizeof(TAudioChan));
|
||||||
@@ -338,13 +337,13 @@ AudioChn Audio_PlaySound(AudioSnd snd, float leftvol, float rightvol, int loop)
|
|||||||
// Initialize the channel
|
// Initialize the channel
|
||||||
chan->wave = wave;
|
chan->wave = wave;
|
||||||
chan->pos = 0;
|
chan->pos = 0;
|
||||||
chan->rightvol = (rightvol * 255);
|
chan->rightVolume = (uint8_t)(rightVolume * 255.0f);
|
||||||
chan->leftvol = (leftvol * 255);
|
chan->leftVolume = (uint8_t)(leftVolume * 255.0f);
|
||||||
chan->loop = loop;
|
chan->loop = loop;
|
||||||
|
|
||||||
// Include in sounds list
|
// Include in sounds list
|
||||||
chan->next = _channels;
|
chan->next = g_Channels;
|
||||||
_channels = chan;
|
g_Channels = chan;
|
||||||
|
|
||||||
return chan;
|
return chan;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _AUDIO_H_
|
#ifndef Audio_H
|
||||||
#define _AUDIO_H_
|
#define Audio_H
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Audio_Init
|
// Audio_Init
|
||||||
@@ -37,7 +37,7 @@ AudioSnd Audio_LoadSound(char *filename);
|
|||||||
// Audio_PlaySound
|
// Audio_PlaySound
|
||||||
//
|
//
|
||||||
// Loads a sound, giving a reference.
|
// Loads a sound, giving a reference.
|
||||||
AudioChn Audio_PlaySound(AudioSnd snd, float leftvol, float rightvol, int loop);
|
AudioChn Audio_PlaySound(AudioSnd snd, float leftVolume, float rightVolume, int loop);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Audio_StopChan
|
// Audio_StopChan
|
||||||
|
|||||||
432
src/Draw.c
432
src/Draw.c
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2011-2015 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Linux
|
// Linux + Emscripten
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -60,21 +60,21 @@ struct TDrawImage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
static SDL_Window *_window = NULL;
|
static SDL_Window *g_Window = NULL;
|
||||||
static SDL_GLContext _glcontext = NULL;
|
static SDL_GLContext g_GLContext = NULL;
|
||||||
static SDL_Renderer *_renderer = NULL;
|
static SDL_Renderer *g_Renderer = NULL;
|
||||||
int _width;
|
int g_Width;
|
||||||
int _height;
|
int g_Height;
|
||||||
long long proc_t_frame = 33333;
|
long long g_ProcTFrame = 33333;
|
||||||
long long draw_t_frame = 16667;
|
long long g_DrawTFrame = 16667;
|
||||||
int _fps = 60;
|
int g_FPS = 60;
|
||||||
QuadArray2D _quadArray = NULL;
|
QuadArray2D g_QuadArray = NULL;
|
||||||
DrawImage _currentImg = NULL;
|
DrawImage g_CurrentImg = NULL;
|
||||||
float _color[4];
|
float g_Color[4];
|
||||||
|
|
||||||
#if USE_OpenGLES
|
#if USE_OpenGLES
|
||||||
|
|
||||||
GLuint _whiteTex;
|
GLuint g_WhiteTex;
|
||||||
|
|
||||||
GLuint Draw_CompileShader(GLenum type, const char *source) {
|
GLuint Draw_CompileShader(GLenum type, const char *source) {
|
||||||
char *strType = type == GL_VERTEX_SHADER ? "VertexShader"
|
char *strType = type == GL_VERTEX_SHADER ? "VertexShader"
|
||||||
@@ -82,7 +82,7 @@ GLuint Draw_CompileShader(GLenum type, const char *source) {
|
|||||||
: "unknownShader";
|
: "unknownShader";
|
||||||
GLuint shader = glCreateShader(type);
|
GLuint shader = glCreateShader(type);
|
||||||
if (shader == 0) {
|
if (shader == 0) {
|
||||||
Print("Error creating shader of type: %s\n", strType);
|
Print("ERROR: Creating shader of type: %s\n", strType);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ GLuint Draw_CompileShader(GLenum type, const char *source) {
|
|||||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
|
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||||
GLchar strInfoLog[infoLogLength + 1];
|
GLchar strInfoLog[infoLogLength + 1];
|
||||||
glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);
|
glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);
|
||||||
Print("Error compiling shader of type: %s: %s\n", strType, strInfoLog);
|
Print("ERROR: Compiling shader of type: %s: %s\n", strType, strInfoLog);
|
||||||
|
|
||||||
glDeleteShader(shader);
|
glDeleteShader(shader);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -131,16 +131,16 @@ GLuint Draw_BuildProgram(const char *vertexShaderSource, const char *fragmentSha
|
|||||||
return programObject;
|
return programObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint programObject;
|
GLuint g_ProgramObject;
|
||||||
|
|
||||||
GLuint vertPosLoc;
|
GLint g_VertPosLoc;
|
||||||
GLuint vertTexLoc;
|
GLint g_VertTexLoc;
|
||||||
GLuint vertColorLoc;
|
GLint g_VertColorLoc;
|
||||||
|
|
||||||
GLuint textureLoc;
|
GLint g_TextureLoc;
|
||||||
GLuint projectionMatrixLoc;
|
GLint g_ProjectionMatrixLoc;
|
||||||
|
|
||||||
GLuint vertexObject;
|
GLuint g_VertexObject;
|
||||||
|
|
||||||
#define Max_Vertices 6000
|
#define Max_Vertices 6000
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ GLuint Draw_UploadGLTexture(int w, int h, unsigned char *pixels);
|
|||||||
// Draw_Init
|
// Draw_Init
|
||||||
//
|
//
|
||||||
// Initializes the game window.
|
// 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) {
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#ifndef ATTACH_PARENT_PROCESS
|
#ifndef ATTACH_PARENT_PROCESS
|
||||||
@@ -173,11 +173,11 @@ int Draw_Init(int width, int height, char *title, int pfps, int fps) {
|
|||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
// Set globals
|
// Set globals
|
||||||
proc_t_frame = 1000000 / pfps;
|
g_ProcTFrame = 1000000 / pFps;
|
||||||
draw_t_frame = 1000000 / fps;
|
g_DrawTFrame = 1000000 / fps;
|
||||||
_fps = fps;
|
g_FPS = fps;
|
||||||
_width = width;
|
g_Width = width;
|
||||||
_height = height;
|
g_Height = height;
|
||||||
|
|
||||||
// Initialize SDL
|
// Initialize SDL
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||||
@@ -187,16 +187,16 @@ int Draw_Init(int width, int height, char *title, int pfps, int fps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize video mode
|
// Initialize video mode
|
||||||
_window =
|
g_Window =
|
||||||
SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
|
SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
|
||||||
if (_window == NULL) {
|
if (g_Window == NULL) {
|
||||||
Print("Draw_Init: Failure initializing video mode.\n");
|
Print("Draw_Init: Failure initializing video mode.\n");
|
||||||
Print("\tSDL Error: %s\n", SDL_GetError());
|
Print("\tSDL Error: %s\n", SDL_GetError());
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
_glcontext = SDL_GL_CreateContext(_window);
|
g_GLContext = SDL_GL_CreateContext(g_Window);
|
||||||
|
|
||||||
_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
|
g_Renderer = SDL_CreateRenderer(g_Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
|
||||||
|
|
||||||
Draw_ShowInfo();
|
Draw_ShowInfo();
|
||||||
|
|
||||||
@@ -211,11 +211,11 @@ int Draw_Init(int width, int height, char *title, int pfps, int fps) {
|
|||||||
|
|
||||||
// Triplebuffer swap
|
// Triplebuffer swap
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
SDL_GL_SwapWindow(_window);
|
SDL_GL_SwapWindow(g_Window);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
SDL_GL_SwapWindow(_window);
|
SDL_GL_SwapWindow(g_Window);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
SDL_GL_SwapWindow(_window);
|
SDL_GL_SwapWindow(g_Window);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
@@ -254,48 +254,48 @@ int Draw_Init(int width, int height, char *title, int pfps, int fps) {
|
|||||||
" gl_FragColor = texture2D(sTexture, vTexCoord)*vColor; \n"
|
" gl_FragColor = texture2D(sTexture, vTexCoord)*vColor; \n"
|
||||||
"} \n";
|
"} \n";
|
||||||
|
|
||||||
programObject = Draw_BuildProgram(vertexShaderSource, fragmentShaderSource_20);
|
g_ProgramObject = Draw_BuildProgram(vertexShaderSource, fragmentShaderSource_20);
|
||||||
if (programObject == 0) {
|
if (g_ProgramObject == 0) {
|
||||||
programObject = Draw_BuildProgram(vertexShaderSource, fragmentShaderSource_10);
|
g_ProgramObject = Draw_BuildProgram(vertexShaderSource, fragmentShaderSource_10);
|
||||||
}
|
}
|
||||||
glUseProgram(programObject);
|
glUseProgram(g_ProgramObject);
|
||||||
|
|
||||||
vertPosLoc = glGetAttribLocation(programObject, "aPosition");
|
g_VertPosLoc = glGetAttribLocation(g_ProgramObject, "aPosition");
|
||||||
vertTexLoc = glGetAttribLocation(programObject, "aTexCoord");
|
g_VertTexLoc = glGetAttribLocation(g_ProgramObject, "aTexCoord");
|
||||||
vertColorLoc = glGetAttribLocation(programObject, "aColor");
|
g_VertColorLoc = glGetAttribLocation(g_ProgramObject, "aColor");
|
||||||
|
|
||||||
textureLoc = glGetUniformLocation(programObject, "sTexture");
|
g_TextureLoc = glGetUniformLocation(g_ProgramObject, "sTexture");
|
||||||
projectionMatrixLoc = glGetUniformLocation(programObject, "sProjectionMatrix");
|
g_ProjectionMatrixLoc = glGetUniformLocation(g_ProgramObject, "sProjectionMatrix");
|
||||||
|
|
||||||
glUniform1i(textureLoc, 0);
|
glUniform1i(g_TextureLoc, 0);
|
||||||
|
|
||||||
glGenBuffers(1, &vertexObject);
|
glGenBuffers(1, &g_VertexObject);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexObject);
|
glBindBuffer(GL_ARRAY_BUFFER, g_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);
|
glBindBuffer(GL_ARRAY_BUFFER, g_VertexObject);
|
||||||
|
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
vertPosLoc, 2, GL_FLOAT, GL_FALSE, Vertex2D_Length * sizeof(float), (void *)(0 * sizeof(float)));
|
g_VertPosLoc, 2, GL_FLOAT, GL_FALSE, Vertex2D_Length * sizeof(float), (void *)(0 * sizeof(float)));
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
vertTexLoc, 2, GL_FLOAT, GL_FALSE, Vertex2D_Length * sizeof(float), (void *)(2 * sizeof(float)));
|
g_VertTexLoc, 2, GL_FLOAT, GL_FALSE, Vertex2D_Length * sizeof(float), (void *)(2 * sizeof(float)));
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
vertColorLoc, 4, GL_FLOAT, GL_FALSE, Vertex2D_Length * sizeof(float), (void *)(4 * sizeof(float)));
|
g_VertColorLoc, 4, GL_FLOAT, GL_FALSE, Vertex2D_Length * sizeof(float), (void *)(4 * sizeof(float)));
|
||||||
|
|
||||||
glEnableVertexAttribArray(vertPosLoc);
|
glEnableVertexAttribArray(g_VertPosLoc);
|
||||||
glEnableVertexAttribArray(vertTexLoc);
|
glEnableVertexAttribArray(g_VertTexLoc);
|
||||||
glEnableVertexAttribArray(vertColorLoc);
|
glEnableVertexAttribArray(g_VertColorLoc);
|
||||||
|
|
||||||
unsigned char whiteTexData[4] = {255, 255, 255, 255};
|
unsigned char whiteTexData[4] = {255, 255, 255, 255};
|
||||||
_whiteTex = Draw_UploadGLTexture(1, 1, whiteTexData);
|
g_WhiteTex = Draw_UploadGLTexture(1, 1, whiteTexData);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set the proyection (2D)
|
// Set the projection (2D)
|
||||||
glViewport(0, 0, _width, _height);
|
glViewport(0, 0, g_Width, g_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[0] = (2.0f / (float)g_Width);
|
||||||
projectionMatrix[5] = -(2.0f / _height);
|
projectionMatrix[5] = -(2.0f / (float)g_Height);
|
||||||
projectionMatrix[10] = -0.001f;
|
projectionMatrix[10] = -0.001f;
|
||||||
projectionMatrix[3] = -1.0f;
|
projectionMatrix[3] = -1.0f;
|
||||||
projectionMatrix[7] = 1.0f;
|
projectionMatrix[7] = 1.0f;
|
||||||
@@ -306,7 +306,7 @@ int Draw_Init(int width, int height, char *title, int pfps, int fps) {
|
|||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// Initialize the triangle array
|
// Initialize the triangle array
|
||||||
_quadArray = QuadArray2D_Create(400);
|
g_QuadArray = QuadArray2D_Create(400);
|
||||||
|
|
||||||
Draw_SetColor(1.0f, 1.0f, 1.0f, 1.0f);
|
Draw_SetColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
@@ -327,10 +327,6 @@ void Draw_ShowInfo() {
|
|||||||
Print(" Renderer: %s\n", str);
|
Print(" Renderer: %s\n", str);
|
||||||
str = (char *)glGetString(GL_VERSION);
|
str = (char *)glGetString(GL_VERSION);
|
||||||
Print(" Version: %s\n", str);
|
Print(" Version: %s\n", str);
|
||||||
GLint major, minor;
|
|
||||||
glGetIntegerv(GL_MAJOR_VERSION, &major);
|
|
||||||
glGetIntegerv(GL_MINOR_VERSION, &minor);
|
|
||||||
Print(" Version : %d.%d\n", major, minor);
|
|
||||||
str = (char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
str = (char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||||
Print(" Shader Version: %s\n", str);
|
Print(" Shader Version: %s\n", str);
|
||||||
Print("*********************************\n");
|
Print("*********************************\n");
|
||||||
@@ -362,7 +358,7 @@ void Draw_SetMatrix(float matrix[16]) {
|
|||||||
glLoadMatrixf(tempMatrix);
|
glLoadMatrixf(tempMatrix);
|
||||||
#endif
|
#endif
|
||||||
#if USE_OpenGLES
|
#if USE_OpenGLES
|
||||||
glUniformMatrix4fv(projectionMatrixLoc, 1, GL_FALSE, matrix);
|
glUniformMatrix4fv(g_ProjectionMatrixLoc, 1, GL_FALSE, matrix);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,32 +393,33 @@ GLuint Draw_UploadGLTexture(int w, int h, unsigned char *pixels) {
|
|||||||
//
|
//
|
||||||
// Performs all the queued draw actions.
|
// Performs all the queued draw actions.
|
||||||
void Draw_Flush() {
|
void Draw_Flush() {
|
||||||
if (_currentImg == NULL || _quadArray->nVertex <= 0) {
|
if (g_CurrentImg == NULL || g_QuadArray->nVertex <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_currentImg->tex == -1) {
|
if (g_CurrentImg->tex == -1) {
|
||||||
_currentImg->tex = Draw_UploadGLTexture(_currentImg->w, _currentImg->h, _currentImg->data);
|
g_CurrentImg->tex = Draw_UploadGLTexture(g_CurrentImg->w, g_CurrentImg->h, g_CurrentImg->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_OpenGL
|
#if USE_OpenGL
|
||||||
// Draw the quad array
|
// Draw the quad array
|
||||||
glBindTexture(GL_TEXTURE_2D, _currentImg->tex);
|
glBindTexture(GL_TEXTURE_2D, g_CurrentImg->tex);
|
||||||
glColorPointer(4, GL_FLOAT, Vertex2D_Length * sizeof(float), (GLvoid *)(_quadArray->vertexData + 4));
|
glColorPointer(4, GL_FLOAT, Vertex2D_Length * sizeof(float), (GLvoid *)(g_QuadArray->vertexData + 4));
|
||||||
glTexCoordPointer(2, GL_FLOAT, Vertex2D_Length * sizeof(float), (GLvoid *)(_quadArray->vertexData + 2));
|
glTexCoordPointer(2, GL_FLOAT, Vertex2D_Length * sizeof(float), (GLvoid *)(g_QuadArray->vertexData + 2));
|
||||||
glVertexPointer(2, GL_FLOAT, Vertex2D_Length * sizeof(float), (GLvoid *)(_quadArray->vertexData));
|
glVertexPointer(2, GL_FLOAT, Vertex2D_Length * sizeof(float), (GLvoid *)(g_QuadArray->vertexData));
|
||||||
glDrawArrays(GL_TRIANGLES, 0, _quadArray->nVertex);
|
glDrawArrays(GL_TRIANGLES, 0, g_QuadArray->nVertex);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Draw the quad array
|
// Draw the quad array
|
||||||
glBindTexture(GL_TEXTURE_2D, _currentImg->tex);
|
glBindTexture(GL_TEXTURE_2D, g_CurrentImg->tex);
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, Vertex2D_Length * sizeof(float) * _quadArray->nVertex, _quadArray->vertexData);
|
glBufferSubData(
|
||||||
glDrawArrays(GL_TRIANGLES, 0, _quadArray->nVertex);
|
GL_ARRAY_BUFFER, 0, Vertex2D_Length * sizeof(float) * g_QuadArray->nVertex, g_QuadArray->vertexData);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, g_QuadArray->nVertex);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Empty it
|
// Empty it
|
||||||
QuadArray2D_Clean(_quadArray);
|
QuadArray2D_Clean(g_QuadArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -435,35 +432,37 @@ void Draw_Clean(unsigned char r, unsigned char g, unsigned char b) {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
#else
|
#else
|
||||||
Draw_Flush();
|
Draw_Flush();
|
||||||
float fr = r / 255.0f;
|
float fr = (float)r / 255.0f;
|
||||||
float fg = g / 255.0f;
|
float fg = (float)g / 255.0f;
|
||||||
float fb = b / 255.0f;
|
float fb = (float)b / 255.0f;
|
||||||
|
float fWidth = (float)g_Width;
|
||||||
|
float fHeight = (float)g_Height;
|
||||||
GLfloat vVertices[] = {
|
GLfloat vVertices[] = {
|
||||||
0.0, 0.0, // Position 0
|
0.0f, 0.0f, // Position 0
|
||||||
0.0, 0.0, // TexCoord 0
|
0.0f, 0.0f, // TexCoord 0
|
||||||
fr, fg, fb, 1.0, // Color
|
fr, fg, fb, 1.0f, // Color
|
||||||
|
|
||||||
0.0, _height, // Position 1
|
0.0f, fHeight, // Position 1
|
||||||
0.0, 1.0, // TexCoord 1
|
0.0f, 1.0f, // TexCoord 1
|
||||||
fr, fg, fb, 1.0, // Color
|
fr, fg, fb, 1.0f, // Color
|
||||||
|
|
||||||
_width, _height, // Position 2
|
fWidth, fHeight, // Position 2
|
||||||
1.0, 1.0, // TexCoord 2
|
1.0f, 1.0f, // TexCoord 2
|
||||||
fr, fg, fb, 1.0, // Color
|
fr, fg, fb, 1.0f, // Color
|
||||||
|
|
||||||
_width, _height, // Position 2
|
fWidth, fHeight, // Position 2
|
||||||
1.0, 1.0, // TexCoord 2
|
1.0f, 1.0f, // TexCoord 2
|
||||||
fr, fg, fb, 1.0, // Color
|
fr, fg, fb, 1.0f, // Color
|
||||||
|
|
||||||
_width, 0.0, // Position 3
|
fWidth, 0.0f, // Position 3
|
||||||
1.0, 0.0, // TexCoord 3
|
1.0f, 0.0f, // TexCoord 3
|
||||||
fr, fg, fb, 1.0, // Color
|
fr, fg, fb, 1.0f, // Color
|
||||||
|
|
||||||
0.0, 0.0, // Position 0
|
0.0f, 0.0f, // Position 0
|
||||||
0.0, 0.0, // TexCoord 0
|
0.0f, 0.0f, // TexCoord 0
|
||||||
fr, fg, fb, 1.0, // Color
|
fr, fg, fb, 1.0f, // Color
|
||||||
};
|
};
|
||||||
glBindTexture(GL_TEXTURE_2D, _whiteTex);
|
glBindTexture(GL_TEXTURE_2D, g_WhiteTex);
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vVertices), vVertices);
|
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vVertices), vVertices);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
#endif
|
#endif
|
||||||
@@ -472,13 +471,13 @@ void Draw_Clean(unsigned char r, unsigned char g, unsigned char b) {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_LoopIteration
|
// Draw_LoopIteration
|
||||||
//
|
//
|
||||||
// One iteracion of the loop updating the game window.
|
// One iteration of the loop updating the game window.
|
||||||
void (*_proc_func)(void *data) = NULL;
|
void (*g_ProcFunc)(void *data) = NULL;
|
||||||
void (*_draw_func)(void *data, float f) = NULL;
|
void (*g_DrawFunc)(void *data, float f) = NULL;
|
||||||
void *_data = NULL;
|
void *g_Data = NULL;
|
||||||
int _draw_looping = 0;
|
int g_DrawLooping = 0;
|
||||||
int _draw_exitoverrided = 0;
|
int g_DrawExitOverride = 0;
|
||||||
long long _accTime;
|
long long g_AccumulatedTime;
|
||||||
int Draw_LoopIteration() {
|
int Draw_LoopIteration() {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
|
||||||
@@ -494,10 +493,10 @@ int Draw_LoopIteration() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.type == SDL_MOUSEMOTION) {
|
if (event.type == SDL_MOUSEMOTION) {
|
||||||
Input_SetPointerPosition(event.motion.x / (float)_width, event.motion.y / (float)_height);
|
Input_SetPointerPosition(event.motion.x / (float)g_Width, event.motion.y / (float)g_Height);
|
||||||
}
|
}
|
||||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||||
Input_SetPointerPosition(event.button.x / (float)_width, event.button.y / (float)_height);
|
Input_SetPointerPosition(event.button.x / (float)g_Width, event.button.y / (float)g_Height);
|
||||||
Input_SetPointerDown(1);
|
Input_SetPointerDown(1);
|
||||||
}
|
}
|
||||||
if (event.type == SDL_FINGERMOTION) {
|
if (event.type == SDL_FINGERMOTION) {
|
||||||
@@ -508,7 +507,7 @@ int Draw_LoopIteration() {
|
|||||||
Input_SetPointerDown(1);
|
Input_SetPointerDown(1);
|
||||||
}
|
}
|
||||||
if (event.type == SDL_MOUSEBUTTONUP) {
|
if (event.type == SDL_MOUSEBUTTONUP) {
|
||||||
Input_SetPointerPosition(event.button.x / (float)_width, event.button.y / (float)_height);
|
Input_SetPointerPosition(event.button.x / (float)g_Width, event.button.y / (float)g_Height);
|
||||||
Input_SetPointerDown(0);
|
Input_SetPointerDown(0);
|
||||||
}
|
}
|
||||||
if (event.type == SDL_FINGERUP) {
|
if (event.type == SDL_FINGERUP) {
|
||||||
@@ -520,41 +519,41 @@ int Draw_LoopIteration() {
|
|||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
if (event.type == SDL_QUIT) {
|
if (event.type == SDL_QUIT) {
|
||||||
Input_SetKey(InputKey_Exit, 1);
|
Input_SetKey(InputKey_Exit, 1);
|
||||||
if (!_draw_exitoverrided) {
|
if (!g_DrawExitOverride) {
|
||||||
_draw_looping = 0;
|
g_DrawLooping = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.type == SDL_KEYDOWN) {
|
if (event.type == SDL_KEYDOWN) {
|
||||||
if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
|
if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
|
||||||
Input_SetKey(InputKey_Exit, 1);
|
Input_SetKey(InputKey_Exit, 1);
|
||||||
if (!_draw_exitoverrided) {
|
if (!g_DrawExitOverride) {
|
||||||
_draw_looping = 0;
|
g_DrawLooping = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.type == SDL_MOUSEMOTION) {
|
if (event.type == SDL_MOUSEMOTION) {
|
||||||
Input_SetPointerPosition(event.motion.x / (float)_width, event.motion.y / (float)_height);
|
Input_SetPointerPosition((float)event.motion.x / (float)g_Width, (float)event.motion.y / (float)g_Height);
|
||||||
}
|
}
|
||||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||||
Input_SetPointerPosition(event.button.x / (float)_width, event.button.y / (float)_height);
|
Input_SetPointerPosition((float)event.button.x / (float)g_Width, (float)event.button.y / (float)g_Height);
|
||||||
Input_SetPointerDown(1);
|
Input_SetPointerDown(1);
|
||||||
}
|
}
|
||||||
if (event.type == SDL_MOUSEBUTTONUP) {
|
if (event.type == SDL_MOUSEBUTTONUP) {
|
||||||
Input_SetPointerPosition(event.button.x / (float)_width, event.button.y / (float)_height);
|
Input_SetPointerPosition((float)event.button.x / (float)g_Width, (float)event.button.y / (float)g_Height);
|
||||||
Input_SetPointerDown(0);
|
Input_SetPointerDown(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Process
|
// Process
|
||||||
if (_proc_func) {
|
if (g_ProcFunc) {
|
||||||
if (_accTime > 100000) {
|
if (g_AccumulatedTime > 100000) {
|
||||||
_accTime = 100000;
|
g_AccumulatedTime = 100000;
|
||||||
}
|
}
|
||||||
while (_accTime >= proc_t_frame && _draw_looping) {
|
while (g_AccumulatedTime >= g_ProcTFrame && g_DrawLooping) {
|
||||||
Input_Frame();
|
Input_Frame();
|
||||||
_proc_func(_data);
|
g_ProcFunc(g_Data);
|
||||||
_accTime -= proc_t_frame;
|
g_AccumulatedTime -= g_ProcTFrame;
|
||||||
Input_PostFrame();
|
Input_PostFrame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -563,13 +562,13 @@ int Draw_LoopIteration() {
|
|||||||
Audio_Frame();
|
Audio_Frame();
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
SDL_GL_SwapWindow(_window);
|
SDL_GL_SwapWindow(g_Window);
|
||||||
if (_draw_func) {
|
if (g_DrawFunc) {
|
||||||
_draw_func(_data, (float)_accTime / (float)proc_t_frame);
|
g_DrawFunc(g_Data, (float)g_AccumulatedTime / (float)g_ProcTFrame);
|
||||||
Draw_Flush();
|
Draw_Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _draw_looping;
|
return g_DrawLooping;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef EMSCRIPTEN
|
#ifdef EMSCRIPTEN
|
||||||
@@ -580,7 +579,7 @@ void Draw_LoopIterationAux() {
|
|||||||
|
|
||||||
// Update time
|
// Update time
|
||||||
_procTime2 = Time_GetTime();
|
_procTime2 = Time_GetTime();
|
||||||
_accTime += _procTime2 - _procTime1;
|
g_AccumulatedTime += _procTime2 - _procTime1;
|
||||||
_procTime1 = _procTime2;
|
_procTime1 = _procTime2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -591,35 +590,35 @@ void Draw_LoopIterationAux() {
|
|||||||
// Loops updating the game window.
|
// 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;
|
g_ProcFunc = proc;
|
||||||
_draw_func = draw;
|
g_DrawFunc = draw;
|
||||||
_data = data;
|
g_Data = data;
|
||||||
if (_draw_looping) {
|
if (g_DrawLooping) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_draw_looping = 1;
|
g_DrawLooping = 1;
|
||||||
#ifndef EMSCRIPTEN
|
#ifndef EMSCRIPTEN
|
||||||
long long procTime1, procTime2, drawTime1, drawTime2;
|
long long procTime1, procTime2, drawTime1, drawTime2;
|
||||||
_accTime = proc_t_frame;
|
g_AccumulatedTime = g_ProcTFrame;
|
||||||
procTime1 = drawTime1 = Time_GetTime();
|
procTime1 = drawTime1 = Time_GetTime();
|
||||||
while (Draw_LoopIteration()) {
|
while (Draw_LoopIteration()) {
|
||||||
|
|
||||||
// Wait to round draw_t_frame
|
// Wait to round g_DrawTFrame
|
||||||
drawTime2 = Time_GetTime();
|
drawTime2 = Time_GetTime();
|
||||||
Time_Pause(draw_t_frame - (drawTime2 - drawTime1));
|
Time_Pause(g_DrawTFrame - (drawTime2 - drawTime1));
|
||||||
drawTime2 = Time_GetTime();
|
drawTime2 = Time_GetTime();
|
||||||
drawTime1 = drawTime2;
|
drawTime1 = drawTime2;
|
||||||
|
|
||||||
// Update time
|
// Update time
|
||||||
procTime2 = Time_GetTime();
|
procTime2 = Time_GetTime();
|
||||||
_accTime += procTime2 - procTime1;
|
g_AccumulatedTime += procTime2 - procTime1;
|
||||||
procTime1 = procTime2;
|
procTime1 = procTime2;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
_accTime = proc_t_frame;
|
g_AccumulatedTime = g_ProcTFrame;
|
||||||
_procTime1 = Time_GetTime();
|
_procTime1 = Time_GetTime();
|
||||||
if (_fps <= 50) {
|
if (g_FPS <= 50) {
|
||||||
emscripten_set_main_loop(Draw_LoopIterationAux, _fps, 1);
|
emscripten_set_main_loop(Draw_LoopIterationAux, g_FPS, 1);
|
||||||
} else {
|
} else {
|
||||||
emscripten_set_main_loop(Draw_LoopIterationAux, 0, 1);
|
emscripten_set_main_loop(Draw_LoopIterationAux, 0, 1);
|
||||||
}
|
}
|
||||||
@@ -632,7 +631,7 @@ void Draw_Loop(void (*proc)(void *data), void (*draw)(void *data, float f), void
|
|||||||
// Breaks the drawing loop
|
// Breaks the drawing loop
|
||||||
void Draw_BreakLoop() {
|
void Draw_BreakLoop() {
|
||||||
#ifndef EMSCRIPTEN
|
#ifndef EMSCRIPTEN
|
||||||
_draw_looping = 0;
|
g_DrawLooping = 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,7 +639,7 @@ void Draw_BreakLoop() {
|
|||||||
// Draw_OverrideExit
|
// Draw_OverrideExit
|
||||||
//
|
//
|
||||||
// Overrides the default exit mechanism
|
// Overrides the default exit mechanism
|
||||||
void Draw_OverrideExit(int override) { _draw_exitoverrided = override; }
|
void Draw_OverrideExit(int override) { g_DrawExitOverride = override; }
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_CreateImage
|
// Draw_CreateImage
|
||||||
@@ -664,7 +663,7 @@ DrawImg Draw_CreateImage(int w, int h) {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_LoadImage
|
// Draw_LoadImage
|
||||||
//
|
//
|
||||||
// Loads a image, giving a reference.
|
// Loads an image, giving a reference.
|
||||||
DrawImg Draw_LoadImage(char *filename) {
|
DrawImg Draw_LoadImage(char *filename) {
|
||||||
DrawImage image;
|
DrawImage image;
|
||||||
|
|
||||||
@@ -737,17 +736,17 @@ int Draw_GetFlip(DrawImg img) {
|
|||||||
// Draw_DrawImg
|
// Draw_DrawImg
|
||||||
//
|
//
|
||||||
// Draws an image.
|
// Draws an image.
|
||||||
void Draw_DrawImg(DrawImg img, int x, int y, float scale[2]) {
|
void Draw_DrawImg(DrawImg img, int x, int y, const float scale[2]) {
|
||||||
DrawImage image = img;
|
DrawImage image = img;
|
||||||
float x1, x2, y1, y2;
|
float x1, x2, y1, y2;
|
||||||
float u1 = 0.0f, u2 = 1.0f;
|
float u1 = 0.0f, u2 = 1.0f;
|
||||||
float v1 = 0.0f, v2 = 1.0f;
|
float v1 = 0.0f, v2 = 1.0f;
|
||||||
|
|
||||||
// Prepare screen coordinates
|
// Prepare screen coordinates
|
||||||
x1 = x + (image->x * scale[0]);
|
x1 = (float)x + ((float)image->x * scale[0]);
|
||||||
y1 = y + (image->y * scale[1]);
|
y1 = (float)y + ((float)image->y * scale[1]);
|
||||||
x2 = x1 + (image->w * scale[0]);
|
x2 = x1 + ((float)image->w * scale[0]);
|
||||||
y2 = y1 + (image->h * scale[1]);
|
y2 = y1 + ((float)image->h * scale[1]);
|
||||||
|
|
||||||
// Apply flipping
|
// Apply flipping
|
||||||
if (image->flip & 1) {
|
if (image->flip & 1) {
|
||||||
@@ -762,11 +761,11 @@ void Draw_DrawImg(DrawImg img, int x, int y, float scale[2]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw a quad
|
// Draw a quad
|
||||||
if (_currentImg != image) {
|
if (g_CurrentImg != image) {
|
||||||
Draw_Flush();
|
Draw_Flush();
|
||||||
_currentImg = image;
|
g_CurrentImg = image;
|
||||||
}
|
}
|
||||||
QuadArray2D_AddQuad(_quadArray, x1, y1, u1, v1, x2, y2, u2, v2, _color);
|
QuadArray2D_AddQuad(g_QuadArray, x1, y1, u1, v1, x2, y2, u2, v2, g_Color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -775,13 +774,13 @@ void Draw_DrawImg(DrawImg img, int x, int y, float scale[2]) {
|
|||||||
// Draws an image, resizing.
|
// 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) {
|
||||||
DrawImage image = img;
|
DrawImage image = img;
|
||||||
int x1, x2, y1, y2;
|
float x1, x2, y1, y2;
|
||||||
float u1 = 0.0f, u2 = 1.0f;
|
float u1 = 0.0f, u2 = 1.0f;
|
||||||
float v1 = 0.0f, v2 = 1.0f;
|
float v1 = 0.0f, v2 = 1.0f;
|
||||||
|
|
||||||
// Prepare
|
// Prepare
|
||||||
x1 = x + image->x;
|
x1 = (float)x + (float)image->x;
|
||||||
y1 = y + image->y;
|
y1 = (float)y + (float)image->y;
|
||||||
x2 = x1 + w;
|
x2 = x1 + w;
|
||||||
y2 = y1 + h;
|
y2 = y1 + h;
|
||||||
|
|
||||||
@@ -798,36 +797,36 @@ void Draw_DrawImgResized(DrawImg img, int x, int y, float w, float h) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw a quad
|
// Draw a quad
|
||||||
if (_currentImg != image) {
|
if (g_CurrentImg != image) {
|
||||||
Draw_Flush();
|
Draw_Flush();
|
||||||
_currentImg = image;
|
g_CurrentImg = image;
|
||||||
}
|
}
|
||||||
QuadArray2D_AddQuad(_quadArray, x1, y1, u1, v1, x2, y2, u2, v2, _color);
|
QuadArray2D_AddQuad(g_QuadArray, x1, y1, u1, v1, x2, y2, u2, v2, g_Color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_DrawImgPart
|
// Draw_DrawImgPart
|
||||||
//
|
//
|
||||||
// Draws an image part.
|
// Draws an image part.
|
||||||
void Draw_DrawImgPart(DrawImg img, int x, int y, int w, int h, int i, int j, float scale[2]) {
|
void Draw_DrawImgPart(DrawImg img, int x, int y, int w, int h, int i, int j, const float scale[2]) {
|
||||||
DrawImage image = img;
|
DrawImage image = img;
|
||||||
int x1, x2, y1, y2;
|
float x1, x2, y1, y2;
|
||||||
float us, u1, u2;
|
float us, u1, u2;
|
||||||
float vs, v1, v2;
|
float vs, v1, v2;
|
||||||
|
|
||||||
// Prepare screen coordinates
|
// Prepare screen coordinates
|
||||||
x1 = x + (image->x * scale[0]);
|
x1 = (float)x + ((float)image->x * scale[0]);
|
||||||
y1 = y + (image->y * scale[1]);
|
y1 = (float)y + ((float)image->y * scale[1]);
|
||||||
x2 = x1 + (w * scale[0]);
|
x2 = x1 + ((float)w * scale[0]);
|
||||||
y2 = y1 + (h * scale[1]);
|
y2 = y1 + ((float)h * scale[1]);
|
||||||
|
|
||||||
// Prepare image coordinates
|
// Prepare image coordinates
|
||||||
us = 1.0f / image->w;
|
us = 1.0f / (float)image->w;
|
||||||
u1 = us * i * w;
|
u1 = us * (float)(i * w);
|
||||||
u2 = u1 + (us * w);
|
u2 = u1 + (us * (float)w);
|
||||||
vs = 1.0f / image->h;
|
vs = 1.0f / (float)image->h;
|
||||||
v1 = vs * j * h;
|
v1 = vs * (float)(j * h);
|
||||||
v2 = v1 + (vs * h);
|
v2 = v1 + (vs * (float)h);
|
||||||
|
|
||||||
// Apply flipping
|
// Apply flipping
|
||||||
if (image->flip & 1) {
|
if (image->flip & 1) {
|
||||||
@@ -842,33 +841,33 @@ void Draw_DrawImgPart(DrawImg img, int x, int y, int w, int h, int i, int j, flo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw a quad
|
// Draw a quad
|
||||||
if (_currentImg != image) {
|
if (g_CurrentImg != image) {
|
||||||
Draw_Flush();
|
Draw_Flush();
|
||||||
_currentImg = image;
|
g_CurrentImg = image;
|
||||||
}
|
}
|
||||||
QuadArray2D_AddQuad(_quadArray, x1, y1, u1, v1, x2, y2, u2, v2, _color);
|
QuadArray2D_AddQuad(g_QuadArray, x1, y1, u1, v1, x2, y2, u2, v2, g_Color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_DrawImgPartHoriz
|
// Draw_DrawImgPartHoriz
|
||||||
//
|
//
|
||||||
// Draws an image part horizontally.
|
// Draws an image part horizontally.
|
||||||
void Draw_DrawImgPartHoriz(DrawImg img, int x, int y, int w, int i, float scale[2]) {
|
void Draw_DrawImgPartHoriz(DrawImg img, int x, int y, int w, int i, const float scale[2]) {
|
||||||
DrawImage image = img;
|
DrawImage image = img;
|
||||||
int x1, x2, y1, y2;
|
float x1, x2, y1, y2;
|
||||||
float us, u1, u2;
|
float us, u1, u2;
|
||||||
float v1 = 0.0f, v2 = 1.0f;
|
float v1 = 0.0f, v2 = 1.0f;
|
||||||
|
|
||||||
// Prepare screen coordinates
|
// Prepare screen coordinates
|
||||||
x1 = x + (image->x * scale[0]);
|
x1 = (float)x + ((float)image->x * scale[0]);
|
||||||
y1 = y + (image->y * scale[1]);
|
y1 = (float)y + ((float)image->y * scale[1]);
|
||||||
x2 = x1 + (w * scale[0]);
|
x2 = x1 + ((float)w * scale[0]);
|
||||||
y2 = y1 + (image->h * scale[1]);
|
y2 = y1 + ((float)image->h * scale[1]);
|
||||||
|
|
||||||
// Prepare image coordinates
|
// Prepare image coordinates
|
||||||
us = 1.0f / image->w;
|
us = 1.0f / (float)image->w;
|
||||||
u1 = us * i * w;
|
u1 = us * (float)(i * w);
|
||||||
u2 = u1 + us * w;
|
u2 = u1 + (us * (float)w);
|
||||||
|
|
||||||
// Apply flipping
|
// Apply flipping
|
||||||
if (image->flip & 1) {
|
if (image->flip & 1) {
|
||||||
@@ -883,11 +882,11 @@ void Draw_DrawImgPartHoriz(DrawImg img, int x, int y, int w, int i, float scale[
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw a quad
|
// Draw a quad
|
||||||
if (_currentImg != image) {
|
if (g_CurrentImg != image) {
|
||||||
Draw_Flush();
|
Draw_Flush();
|
||||||
_currentImg = image;
|
g_CurrentImg = image;
|
||||||
}
|
}
|
||||||
QuadArray2D_AddQuad(_quadArray, x1, y1, u1, v1, x2, y2, u2, v2, _color);
|
QuadArray2D_AddQuad(g_QuadArray, x1, y1, u1, v1, x2, y2, u2, v2, g_Color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -895,28 +894,29 @@ void Draw_DrawImgPartHoriz(DrawImg img, int x, int y, int w, int i, float scale[
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Draw_ImgParallax(
|
void Draw_ImgParallax(
|
||||||
DrawImg img, int imgSize[2], int imgOffset[2], float parallaxFactor[2], int gamePos[2], int gameSize[2]) {
|
DrawImg img, int imgSize[2], const int imgOffset[2], const float parallaxFactor[2], const int gamePos[2],
|
||||||
int paralaxPos[2];
|
const int gameSize[2]) {
|
||||||
int mult[2];
|
int parallaxPos[2];
|
||||||
|
int multiply[2];
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
paralaxPos[0] = (gamePos[0] * parallaxFactor[0]) + imgOffset[0];
|
parallaxPos[0] = (int)((float)gamePos[0] * parallaxFactor[0]) + imgOffset[0];
|
||||||
paralaxPos[1] = (gamePos[1] * parallaxFactor[1]) + imgOffset[1];
|
parallaxPos[1] = (int)((float)gamePos[1] * parallaxFactor[1]) + imgOffset[1];
|
||||||
|
|
||||||
mult[0] = floor(paralaxPos[0] / imgSize[0]);
|
multiply[0] = (int)floorf((float)parallaxPos[0] / (float)imgSize[0]);
|
||||||
if (paralaxPos[0] < 0) {
|
if (parallaxPos[0] < 0) {
|
||||||
mult[0]--;
|
multiply[0]--;
|
||||||
}
|
}
|
||||||
mult[1] = floor(paralaxPos[1] / imgSize[1]);
|
multiply[1] = (int)floorf((float)parallaxPos[1] / (float)imgSize[1]);
|
||||||
if (paralaxPos[1] < 0) {
|
if (parallaxPos[1] < 0) {
|
||||||
mult[1]--;
|
multiply[1]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
y = (mult[1] * imgSize[1]) - paralaxPos[1];
|
y = (multiply[1] * imgSize[1]) - parallaxPos[1];
|
||||||
while (y < gameSize[1]) {
|
while (y < gameSize[1]) {
|
||||||
x = (mult[0] * imgSize[0]) - paralaxPos[0];
|
x = (multiply[0] * imgSize[0]) - parallaxPos[0];
|
||||||
while (x < gameSize[0]) {
|
while (x < gameSize[0]) {
|
||||||
Draw_DrawImgResized(img, x, y, imgSize[0], imgSize[1]);
|
Draw_DrawImgResized(img, x, y, (float)imgSize[0], (float)imgSize[1]);
|
||||||
x += imgSize[0];
|
x += imgSize[0];
|
||||||
}
|
}
|
||||||
y += imgSize[1];
|
y += imgSize[1];
|
||||||
@@ -928,10 +928,10 @@ void Draw_ImgParallax(
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Draw_SetColor(float r, float g, float b, float a) {
|
void Draw_SetColor(float r, float g, float b, float a) {
|
||||||
_color[0] = r;
|
g_Color[0] = r;
|
||||||
_color[1] = g;
|
g_Color[1] = g;
|
||||||
_color[2] = b;
|
g_Color[2] = b;
|
||||||
_color[3] = a;
|
g_Color[3] = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -948,7 +948,7 @@ typedef struct {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_DefaultImage
|
// Draw_DefaultImage
|
||||||
//
|
//
|
||||||
// Creates a image with the default font.
|
// Creates an image with the default font.
|
||||||
#include "FontData.h"
|
#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;
|
DrawImage img;
|
||||||
@@ -965,7 +965,7 @@ DrawImage Draw_DefaultFontImage(unsigned char r, unsigned char g, unsigned char
|
|||||||
img->data[offset + 0] = r;
|
img->data[offset + 0] = r;
|
||||||
img->data[offset + 1] = g;
|
img->data[offset + 1] = g;
|
||||||
img->data[offset + 2] = b;
|
img->data[offset + 2] = b;
|
||||||
if (((fontdata_8x8[c * 8 + y] >> (7 - x)) & 0x01) == 1) {
|
if (((fontData_8x8[c * 8 + y] >> (7 - x)) & 0x01) == 1) {
|
||||||
img->data[offset + 3] = a;
|
img->data[offset + 3] = a;
|
||||||
} else {
|
} else {
|
||||||
img->data[offset + 3] = 0x00;
|
img->data[offset + 3] = 0x00;
|
||||||
@@ -1020,7 +1020,7 @@ DrawFnt Draw_LoadFont(char *fichero, int min, int max) {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_FontScale
|
// Draw_FontScale
|
||||||
//
|
//
|
||||||
void Draw_FontScale(DrawFnt f, float scale[2]) {
|
void Draw_FontScale(DrawFnt f, const float scale[2]) {
|
||||||
DrawFont *font = f;
|
DrawFont *font = f;
|
||||||
|
|
||||||
font->scale[0] = scale[0];
|
font->scale[0] = scale[0];
|
||||||
@@ -1041,7 +1041,7 @@ void Draw_DrawText(DrawFnt f, char *text, int x, int y) {
|
|||||||
if ((*ptr) < font->max) {
|
if ((*ptr) < font->max) {
|
||||||
Draw_DrawImgPartHoriz(font->img, x, y, font->w, (*ptr) - font->min, font->scale);
|
Draw_DrawImgPartHoriz(font->img, x, y, font->w, (*ptr) - font->min, font->scale);
|
||||||
}
|
}
|
||||||
x += font->w * font->scale[0];
|
x += (int)((float)font->w * font->scale[0]);
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1095,34 +1095,34 @@ void Draw_SaveRGBAToPNG(char *filename, unsigned char *data, int width, int heig
|
|||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_SaveScreenshoot
|
// Draw_SaveScreenshot
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Draw_SaveScreenshoot(char *filename) {
|
void Draw_SaveScreenshot(char *filename) {
|
||||||
#if USE_OpenGL
|
#if USE_OpenGL
|
||||||
unsigned char *pixelData;
|
unsigned char *pixelData;
|
||||||
unsigned char *image_line;
|
unsigned char *image_line;
|
||||||
int i, half_height, line_size;
|
int i, half_height, line_size;
|
||||||
|
|
||||||
pixelData = malloc(_width * _height * 4);
|
pixelData = malloc(g_Width * g_Height * 4);
|
||||||
|
|
||||||
glReadPixels(0, 0, _width, _height, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
|
glReadPixels(0, 0, g_Width, g_Height, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
|
||||||
|
|
||||||
// Flip the image data
|
// Flip the image data
|
||||||
line_size = _width * 4;
|
line_size = g_Width * 4;
|
||||||
half_height = _height / 2;
|
half_height = g_Height / 2;
|
||||||
image_line = malloc(line_size);
|
image_line = malloc(line_size);
|
||||||
for (i = 0; i < half_height; i++) {
|
for (i = 0; i < half_height; i++) {
|
||||||
memcpy(image_line, pixelData + i * line_size, line_size);
|
memcpy(image_line, pixelData + i * line_size, line_size);
|
||||||
memcpy(pixelData + i * line_size, pixelData + (_height - (i + 1)) * line_size, line_size);
|
memcpy(pixelData + i * line_size, pixelData + (g_Height - (i + 1)) * line_size, line_size);
|
||||||
memcpy(pixelData + (_height - (i + 1)) * line_size, image_line, line_size);
|
memcpy(pixelData + (g_Height - (i + 1)) * line_size, image_line, line_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the image
|
// Save the image
|
||||||
if (EndsWith(filename, ".bmp") || EndsWith(filename, ".BMP")) {
|
if (EndsWith(filename, ".bmp") || EndsWith(filename, ".BMP")) {
|
||||||
Draw_SaveRGBAToBMP(filename, pixelData, _width, _height);
|
Draw_SaveRGBAToBMP(filename, pixelData, g_Width, g_Height);
|
||||||
} else if (EndsWith(filename, ".png") || EndsWith(filename, ".PNG")) {
|
} else if (EndsWith(filename, ".png") || EndsWith(filename, ".PNG")) {
|
||||||
Draw_SaveRGBAToPNG(filename, pixelData, _width, _height);
|
Draw_SaveRGBAToPNG(filename, pixelData, g_Width, g_Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
|||||||
26
src/Draw.h
26
src/Draw.h
@@ -1,13 +1,13 @@
|
|||||||
// Copyright (C) 2011-2015 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _DRAW_H_
|
#ifndef Draw_H
|
||||||
#define _DRAW_H_
|
#define Draw_H
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_Init
|
// Draw_Init
|
||||||
//
|
//
|
||||||
// Initializes the game window.
|
// 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
|
// Draw_Clean
|
||||||
@@ -42,7 +42,7 @@ void Draw_Flush();
|
|||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// DrawImg //
|
// DrawImg //
|
||||||
/////////////
|
/////////////
|
||||||
// Reference to a image.
|
// Reference to an image.
|
||||||
typedef void *DrawImg;
|
typedef void *DrawImg;
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -53,7 +53,7 @@ DrawImg Draw_CreateImage(int w, int h);
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_LoadImage
|
// Draw_LoadImage
|
||||||
//
|
//
|
||||||
// Loads a image, giving a reference.
|
// Loads an image, giving a reference.
|
||||||
DrawImg Draw_LoadImage(char *filename);
|
DrawImg Draw_LoadImage(char *filename);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -82,7 +82,7 @@ int Draw_GetFlip(DrawImg img);
|
|||||||
// Draw_DrawImg
|
// Draw_DrawImg
|
||||||
//
|
//
|
||||||
// Draws an image.
|
// Draws an image.
|
||||||
void Draw_DrawImg(DrawImg img, int x, int y, float scale[2]);
|
void Draw_DrawImg(DrawImg img, int x, int y, const float scale[2]);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_DrawImgResized
|
// Draw_DrawImgResized
|
||||||
@@ -94,20 +94,20 @@ void Draw_DrawImgResized(DrawImg img, int x, int y, float w, float h);
|
|||||||
// Draw_DrawImgPart
|
// Draw_DrawImgPart
|
||||||
//
|
//
|
||||||
// Draws an image part.
|
// Draws an image part.
|
||||||
void Draw_DrawImgPart(DrawImg img, int x, int y, int w, int h, int i, int j, float scale[2]);
|
void Draw_DrawImgPart(DrawImg img, int x, int y, int w, int h, int i, int j, const float scale[2]);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_DrawImgPartHoriz
|
// Draw_DrawImgPartHoriz
|
||||||
//
|
//
|
||||||
// Draws an image part horizontally.
|
// Draws an image part horizontally.
|
||||||
void Draw_DrawImgPartHoriz(DrawImg img, int x, int y, int w, int i, float scale[2]);
|
void Draw_DrawImgPartHoriz(DrawImg img, int x, int y, int w, int i, const float scale[2]);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_ImgParallax
|
// Draw_ImgParallax
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Draw_ImgParallax(
|
void Draw_ImgParallax(
|
||||||
DrawImg img, int imgSize[2], int imgOffset[2], float parallaxFactor[2], int gamePos[2], int gameSize[2]);
|
DrawImg img, int imgSize[2], const int imgOffset[2], const float parallaxFactor[2], const int gamePos[2], const int gameSize[2]);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_SetColor
|
// Draw_SetColor
|
||||||
@@ -136,7 +136,7 @@ DrawFnt Draw_LoadFont(char *fichero, int min, int max);
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_FontScale
|
// Draw_FontScale
|
||||||
//
|
//
|
||||||
void Draw_FontScale(DrawFnt f, float scale[2]);
|
void Draw_FontScale(DrawFnt f, const float scale[2]);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_DrawText
|
// Draw_DrawText
|
||||||
@@ -157,10 +157,10 @@ void Draw_SaveRGBAToBMP(char *filename, unsigned char *data, int width, int heig
|
|||||||
void Draw_SaveRGBAToPNG(char *filename, unsigned char *data, int width, int height);
|
void Draw_SaveRGBAToPNG(char *filename, unsigned char *data, int width, int height);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_SaveScreenshoot
|
// Draw_SaveScreenshot
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Draw_SaveScreenshoot(char *filename);
|
void Draw_SaveScreenshot(char *filename);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_ShowCursor
|
// Draw_ShowCursor
|
||||||
|
|||||||
97
src/Entity.c
97
src/Entity.c
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2011-2014 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -16,29 +16,38 @@
|
|||||||
#define EntityIntFlag_UpdateColor 8
|
#define EntityIntFlag_UpdateColor 8
|
||||||
#define EntityIntFlag_UpdatedScale 16
|
#define EntityIntFlag_UpdatedScale 16
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// Entity_GetFree
|
||||||
|
//
|
||||||
|
//
|
||||||
|
Entity g_FreeEntity = NULL;
|
||||||
|
Entity Entity_GetFree() {
|
||||||
|
Entity e;
|
||||||
|
|
||||||
|
if (!g_FreeEntity) {
|
||||||
|
// Allocate a big block of entities
|
||||||
|
int n = 1024, i;
|
||||||
|
TEntity *newEntities = malloc(sizeof(TEntity) * n);
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
if (i < (n - 1)) {
|
||||||
|
newEntities[i].next = &newEntities[i + 1];
|
||||||
|
} else {
|
||||||
|
newEntities[i].next = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_FreeEntity = newEntities;
|
||||||
|
}
|
||||||
|
e = g_FreeEntity;
|
||||||
|
g_FreeEntity = e->next;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Entity_New
|
// Entity_New
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
Entity _free_entity = NULL;
|
|
||||||
Entity Entity_New() {
|
Entity Entity_New() {
|
||||||
Entity e;
|
Entity e = Entity_GetFree();
|
||||||
|
|
||||||
if (!_free_entity) {
|
|
||||||
// Allocate a big block of entities
|
|
||||||
int n = 1024, i;
|
|
||||||
TEntity *newEnts = malloc(sizeof(TEntity) * n);
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
if (i < (n - 1)) {
|
|
||||||
newEnts[i].next = &newEnts[i + 1];
|
|
||||||
} else {
|
|
||||||
newEnts[i].next = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_free_entity = newEnts;
|
|
||||||
}
|
|
||||||
e = _free_entity;
|
|
||||||
_free_entity = e->next;
|
|
||||||
|
|
||||||
e->base = NULL;
|
e->base = NULL;
|
||||||
e->type = 0;
|
e->type = 0;
|
||||||
@@ -114,8 +123,8 @@ void Entity_Destroy(Entity e) {
|
|||||||
if (e->ondelete) {
|
if (e->ondelete) {
|
||||||
e->ondelete(e);
|
e->ondelete(e);
|
||||||
}
|
}
|
||||||
e->next = _free_entity;
|
e->next = g_FreeEntity;
|
||||||
_free_entity = e;
|
g_FreeEntity = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -255,7 +264,7 @@ void Entity_Draw(Entity e, int x, int y, float f) {
|
|||||||
}
|
}
|
||||||
if (e->internalFlags & EntityIntFlag_UpdatedPos) {
|
if (e->internalFlags & EntityIntFlag_UpdatedPos) {
|
||||||
vec2_interpol(fPos, e->pos0, e->pos, f);
|
vec2_interpol(fPos, e->pos0, e->pos, f);
|
||||||
AnimPlay_Draw(&e->anim, fPos[0] + x, fPos[1] + y, scale);
|
AnimPlay_Draw(&e->anim, (int)(fPos[0] + x), fPos[1] + y, scale);
|
||||||
} else {
|
} else {
|
||||||
AnimPlay_Draw(&e->anim, e->pos[0] + x, e->pos[1] + y, scale);
|
AnimPlay_Draw(&e->anim, e->pos[0] + x, e->pos[1] + y, scale);
|
||||||
}
|
}
|
||||||
@@ -357,15 +366,15 @@ void Entity_PostProcess(Entity e, int ft) {
|
|||||||
// CollisionInfo_New
|
// CollisionInfo_New
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
CollisionInfo _free_collInfo = NULL;
|
CollisionInfo g_FreeCollisionInfo = 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, const vec2 n, int applyFriction) {
|
||||||
CollisionInfo collInfo;
|
CollisionInfo collInfo;
|
||||||
|
|
||||||
if (!_free_collInfo) {
|
if (!g_FreeCollisionInfo) {
|
||||||
collInfo = malloc(sizeof(TCollisionInfo));
|
collInfo = malloc(sizeof(TCollisionInfo));
|
||||||
} else {
|
} else {
|
||||||
collInfo = _free_collInfo;
|
collInfo = g_FreeCollisionInfo;
|
||||||
_free_collInfo = collInfo->next;
|
g_FreeCollisionInfo = collInfo->next;
|
||||||
}
|
}
|
||||||
collInfo->next = NULL;
|
collInfo->next = NULL;
|
||||||
|
|
||||||
@@ -392,8 +401,8 @@ void CollisionInfo_Destroy(CollisionInfo *collInfoRef) {
|
|||||||
CollisionInfo nextCollInfo;
|
CollisionInfo nextCollInfo;
|
||||||
while (collInfo != NULL) {
|
while (collInfo != NULL) {
|
||||||
nextCollInfo = collInfo->next;
|
nextCollInfo = collInfo->next;
|
||||||
collInfo->next = _free_collInfo;
|
collInfo->next = g_FreeCollisionInfo;
|
||||||
_free_collInfo = collInfo;
|
g_FreeCollisionInfo = collInfo;
|
||||||
collInfo = nextCollInfo;
|
collInfo = nextCollInfo;
|
||||||
}
|
}
|
||||||
collInfoRef[0] = NULL;
|
collInfoRef[0] = NULL;
|
||||||
@@ -533,7 +542,7 @@ int Entity_CheckCollision(Entity ent1, Entity ent2, CollisionInfo *collInfoRef)
|
|||||||
|
|
||||||
// Circle-Circle test from ent1
|
// Circle-Circle test from ent1
|
||||||
vec2_minus(vel, ent1->vel, ent2->vel);
|
vec2_minus(vel, ent1->vel, ent2->vel);
|
||||||
if (Colision_CircleCircle(ent1->pos, ent1->radius, vel, ent2->pos, ent2->radius, &t, n)) {
|
if (Collision_CircleCircle(ent1->pos, ent1->radius, vel, ent2->pos, ent2->radius, &t, n)) {
|
||||||
CollisionInfo_Add(collInfoRef, CollisionResponse_Circle, ent1, ent2, t, n, 0);
|
CollisionInfo_Add(collInfoRef, CollisionResponse_Circle, ent1, ent2, t, n, 0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -544,7 +553,7 @@ int Entity_CheckCollision(Entity ent1, Entity ent2, CollisionInfo *collInfoRef)
|
|||||||
// Entity_CollisionResponseCircle
|
// Entity_CollisionResponseCircle
|
||||||
//
|
//
|
||||||
// Normal response to a collision between circles.
|
// 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, const vec2 n) {
|
||||||
float moment;
|
float moment;
|
||||||
vec2 temp;
|
vec2 temp;
|
||||||
float elast;
|
float elast;
|
||||||
@@ -716,7 +725,7 @@ void Entity_GetPos(Entity e, vec2 pos) { vec2_copy(pos, e->pos); }
|
|||||||
// Entity_SetPos
|
// Entity_SetPos
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Entity_SetPos(Entity e, vec2 pos) {
|
void Entity_SetPos(Entity e, const vec2 pos) {
|
||||||
vec2_copy(e->pos, pos);
|
vec2_copy(e->pos, pos);
|
||||||
vec2_copy(e->oldpos, pos);
|
vec2_copy(e->oldpos, pos);
|
||||||
vec2_copy(e->pos0, pos);
|
vec2_copy(e->pos0, pos);
|
||||||
@@ -727,7 +736,7 @@ void Entity_SetPos(Entity e, vec2 pos) {
|
|||||||
// Entity_AddPos
|
// Entity_AddPos
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Entity_AddPos(Entity e, vec2 pos) {
|
void Entity_AddPos(Entity e, const vec2 pos) {
|
||||||
vec2_plus(e->pos, e->pos, pos);
|
vec2_plus(e->pos, e->pos, pos);
|
||||||
vec2_copy(e->oldpos, e->pos);
|
vec2_copy(e->oldpos, e->pos);
|
||||||
vec2_copy(e->pos0, e->pos);
|
vec2_copy(e->pos0, e->pos);
|
||||||
@@ -738,7 +747,7 @@ void Entity_AddPos(Entity e, vec2 pos) {
|
|||||||
// Entity_UpdatePos
|
// Entity_UpdatePos
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Entity_UpdatePos(Entity e, vec2 pos) {
|
void Entity_UpdatePos(Entity e, const vec2 pos) {
|
||||||
|
|
||||||
// Mark the update of the position.
|
// Mark the update of the position.
|
||||||
vec2_copy(e->oldpos, e->pos);
|
vec2_copy(e->oldpos, e->pos);
|
||||||
@@ -750,7 +759,7 @@ void Entity_UpdatePos(Entity e, vec2 pos) {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Entity_AddVel
|
// Entity_AddVel
|
||||||
//
|
//
|
||||||
void Entity_AddVel(Entity e, vec2 vel) {
|
void Entity_AddVel(Entity e, const vec2 vel) {
|
||||||
vec2_plus(e->vel, e->vel, vel);
|
vec2_plus(e->vel, e->vel, vel);
|
||||||
Entity_CalcBBox(e);
|
Entity_CalcBBox(e);
|
||||||
}
|
}
|
||||||
@@ -758,7 +767,7 @@ void Entity_AddVel(Entity e, vec2 vel) {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Entity_SetVel
|
// Entity_SetVel
|
||||||
//
|
//
|
||||||
void Entity_SetVel(Entity e, vec2 vel) {
|
void Entity_SetVel(Entity e, const vec2 vel) {
|
||||||
vec2_copy(e->vel, vel);
|
vec2_copy(e->vel, vel);
|
||||||
Entity_CalcBBox(e);
|
Entity_CalcBBox(e);
|
||||||
}
|
}
|
||||||
@@ -783,7 +792,7 @@ void Entity_SetVelV(Entity e, float v) {
|
|||||||
// Entity_AddVelLimit
|
// Entity_AddVelLimit
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Entity_AddVelLimit(Entity e, vec2 vel, float limit) {
|
void Entity_AddVelLimit(Entity e, const vec2 vel, float limit) {
|
||||||
float vlen_orig, vlen;
|
float vlen_orig, vlen;
|
||||||
vec2 dir, vel_temp;
|
vec2 dir, vel_temp;
|
||||||
|
|
||||||
@@ -915,7 +924,7 @@ void Entity_SetDefaultColor(Entity e, float r, float g, float b, float a) {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Entity_SetScale
|
// Entity_SetScale
|
||||||
//
|
//
|
||||||
void Entity_SetScale(Entity e, float scale[2]) {
|
void Entity_SetScale(Entity e, const float scale[2]) {
|
||||||
e->scale[0] = scale[0];
|
e->scale[0] = scale[0];
|
||||||
e->scale[1] = scale[1];
|
e->scale[1] = scale[1];
|
||||||
e->internalFlags |= EntityIntFlag_UpdatedScale;
|
e->internalFlags |= EntityIntFlag_UpdatedScale;
|
||||||
@@ -933,7 +942,7 @@ void Entity_GetScale(Entity e, float scale[2]) {
|
|||||||
// Entity_Iluminate
|
// Entity_Iluminate
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void Entity_Iluminate(Entity e, Entity *elist, int n) {
|
void Entity_Iluminate(Entity e, Entity *entityList, int n) {
|
||||||
int i;
|
int i;
|
||||||
vec2 vdist;
|
vec2 vdist;
|
||||||
float qdist, f;
|
float qdist, f;
|
||||||
@@ -951,15 +960,17 @@ void Entity_Iluminate(Entity e, Entity *elist, int n) {
|
|||||||
e->color[3] = e->color[3];
|
e->color[3] = e->color[3];
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (e == elist[i] || !(elist[i]->flags & EntityFlag_Light))
|
if (e == entityList[i] || !(entityList[i]->flags & EntityFlag_Light)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
vec2_minus(vdist, e->pos, elist[i]->pos);
|
vec2_minus(vdist, e->pos, entityList[i]->pos);
|
||||||
qdist = vec2_dot(vdist, vdist);
|
qdist = vec2_dot(vdist, vdist);
|
||||||
qrad = elist[i]->light[3] * elist[i]->light[3];
|
qrad = entityList[i]->light[3] * entityList[i]->light[3];
|
||||||
if (qdist < qrad) {
|
if (qdist < qrad) {
|
||||||
f = 1.0f - 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 * entityList[i]->light[0], f * entityList[i]->light[1], f * entityList[i]->light[2], 0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
src/Entity.h
31
src/Entity.h
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2011-2014 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _ENTITY_H_
|
#ifndef Entity_H
|
||||||
#define _ENTITY_H_
|
#define Entity_H
|
||||||
|
|
||||||
#include "Anim.h"
|
#include "Anim.h"
|
||||||
#include "Draw.h"
|
#include "Draw.h"
|
||||||
@@ -80,6 +80,11 @@ struct TEntity {
|
|||||||
Entity next;
|
Entity next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// Entity_GetFree
|
||||||
|
//
|
||||||
|
Entity Entity_GetFree();
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Entity_New
|
// Entity_New
|
||||||
//
|
//
|
||||||
@@ -153,7 +158,7 @@ struct TCollisionInfo {
|
|||||||
// CollisionInfo_New
|
// 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, const vec2 n, int applyFriction);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// CollisionInfo_Destroy
|
// CollisionInfo_Destroy
|
||||||
@@ -184,7 +189,7 @@ int Entity_CheckCollision(Entity ent1, Entity ent2, CollisionInfo *collInfoRef);
|
|||||||
// Entity_CollisionResponseClircle
|
// Entity_CollisionResponseClircle
|
||||||
//
|
//
|
||||||
// Normal response to a collision of spheres.
|
// 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, const vec2 n);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Entity_CollisionResponseLine
|
// Entity_CollisionResponseLine
|
||||||
@@ -210,9 +215,9 @@ void Entity_Overlaps(Entity b1, Entity b2);
|
|||||||
// Entity_UpdatePos
|
// Entity_UpdatePos
|
||||||
//
|
//
|
||||||
void Entity_GetPos(Entity e, vec2 pos);
|
void Entity_GetPos(Entity e, vec2 pos);
|
||||||
void Entity_SetPos(Entity e, vec2 pos);
|
void Entity_SetPos(Entity e, const vec2 pos);
|
||||||
void Entity_AddPos(Entity e, vec2 pos);
|
void Entity_AddPos(Entity e, const vec2 pos);
|
||||||
void Entity_UpdatePos(Entity e, vec2 pos);
|
void Entity_UpdatePos(Entity e, const vec2 pos);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Entity_AddVel
|
// Entity_AddVel
|
||||||
@@ -223,11 +228,11 @@ void Entity_UpdatePos(Entity e, vec2 pos);
|
|||||||
// Entity_AddVelLimitH
|
// Entity_AddVelLimitH
|
||||||
// Entity_AddVelLimitH
|
// Entity_AddVelLimitH
|
||||||
//
|
//
|
||||||
void Entity_AddVel(Entity e, vec2 vel);
|
void Entity_AddVel(Entity e, const vec2 vel);
|
||||||
void Entity_SetVel(Entity e, vec2 vel);
|
void Entity_SetVel(Entity e, const vec2 vel);
|
||||||
void Entity_SetVelH(Entity e, float v);
|
void Entity_SetVelH(Entity e, float v);
|
||||||
void Entity_SetVelV(Entity e, float v);
|
void Entity_SetVelV(Entity e, float v);
|
||||||
void Entity_AddVelLimit(Entity e, vec2 vel, float limit);
|
void Entity_AddVelLimit(Entity e, const vec2 vel, float limit);
|
||||||
void Entity_AddVelLimitH(Entity e, float v, float limit);
|
void Entity_AddVelLimitH(Entity e, float v, float limit);
|
||||||
void Entity_AddVelLimitV(Entity e, float v, float limit);
|
void Entity_AddVelLimitV(Entity e, float v, float limit);
|
||||||
|
|
||||||
@@ -248,13 +253,13 @@ void Entity_SetDefaultColor(Entity e, float r, float g, float b, float a);
|
|||||||
// Entity_SetScale
|
// Entity_SetScale
|
||||||
// Entity_GetScale
|
// Entity_GetScale
|
||||||
//
|
//
|
||||||
void Entity_SetScale(Entity e, float scale[2]);
|
void Entity_SetScale(Entity e, const float scale[2]);
|
||||||
void Entity_GetScale(Entity e, float scale[2]);
|
void Entity_GetScale(Entity e, float scale[2]);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Entity_Iluminate
|
// Entity_Iluminate
|
||||||
//
|
//
|
||||||
void Entity_Iluminate(Entity e, Entity *elist, int n);
|
void Entity_Iluminate(Entity e, Entity *entityList, int n);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Entity_MarkUpdateLight
|
// Entity_MarkUpdateLight
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
static unsigned char fontdata_8x8[2048] = {
|
static unsigned char fontData_8x8[2048] = {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||||
|
|||||||
444
src/GameLib.c
444
src/GameLib.c
@@ -1,38 +1,29 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <SDL.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "Anim.h"
|
|
||||||
#include "Audio.h"
|
|
||||||
#include "Draw.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
#include "Input.h"
|
|
||||||
#include "TimeUtils.h"
|
|
||||||
#include "Util.h"
|
|
||||||
|
|
||||||
#include "GameLib.h"
|
#include "GameLib.h"
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
Entity *_entity = NULL;
|
Entity *g_Entity = NULL;
|
||||||
int *_entity_flag = NULL;
|
int *g_EntityFlag = NULL;
|
||||||
int _n_entities = 0;
|
int g_NumEntities = 0;
|
||||||
int _n_entities_res = 0;
|
int g_NumEntitiesAllocated = 0;
|
||||||
int _entities_lock = 0;
|
int g_EntitiesLock = 0;
|
||||||
int _entities_compactate = 0;
|
int g_EntitiesCompactate = 0;
|
||||||
void (*_gameproc)() = NULL;
|
void (*g_GameProcFunc)() = NULL;
|
||||||
void (*_gamepostproc)() = NULL;
|
void (*g_GamePostProcFunc)() = NULL;
|
||||||
void (*_gamepredraw)(float f) = NULL;
|
void (*g_GamePreDrawFunc)(float f) = NULL;
|
||||||
void (*_gamedraw)(float f) = NULL;
|
void (*g_GameDrawFunc)(float f) = NULL;
|
||||||
int _pft;
|
int g_ProcFt;
|
||||||
int _game_size[2];
|
int g_GameSize[2];
|
||||||
int _game_pos0[2];
|
int g_GamePos0[2];
|
||||||
int _game_pos1[2];
|
int g_GamePos1[2];
|
||||||
int _game_posOffset[2];
|
int g_GamePosOffset[2];
|
||||||
|
|
||||||
long long t_proc;
|
long long t_proc;
|
||||||
long long t_col;
|
long long t_col;
|
||||||
@@ -50,17 +41,15 @@ struct TParallaxBackground {
|
|||||||
float parallaxFactor[2];
|
float parallaxFactor[2];
|
||||||
};
|
};
|
||||||
#define MaxParallaxBackgrounds 10
|
#define MaxParallaxBackgrounds 10
|
||||||
TParallaxBackground _parallaxBackground[MaxParallaxBackgrounds];
|
TParallaxBackground g_ParallaxBackground[MaxParallaxBackgrounds];
|
||||||
int _nParallaxBackgrounds = 0;
|
int g_NumParallaxBackgrounds = 0;
|
||||||
|
|
||||||
int gamelib_debug = 0;
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// GameLib_Init
|
// GameLib_Init
|
||||||
//
|
//
|
||||||
// Initializes the game.
|
// 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) {
|
||||||
if (!Draw_Init(w, h, title, pfps, fps)) {
|
if (!Draw_Init(w, h, title, pFps, fps)) {
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (!Input_Init()) {
|
if (!Input_Init()) {
|
||||||
@@ -68,14 +57,14 @@ int GameLib_Init(int w, int h, char *title, int pfps, int fps) {
|
|||||||
}
|
}
|
||||||
Audio_Init();
|
Audio_Init();
|
||||||
|
|
||||||
_game_size[0] = w;
|
g_GameSize[0] = w;
|
||||||
_game_size[1] = h;
|
g_GameSize[1] = h;
|
||||||
_game_pos0[0] = 0;
|
g_GamePos0[0] = 0;
|
||||||
_game_pos0[1] = 0;
|
g_GamePos0[1] = 0;
|
||||||
_game_pos1[0] = 0;
|
g_GamePos1[0] = 0;
|
||||||
_game_pos1[1] = 0;
|
g_GamePos1[1] = 0;
|
||||||
|
|
||||||
_pft = 1000 / pfps;
|
g_ProcFt = 1000 / pFps;
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -85,37 +74,38 @@ int GameLib_Init(int w, int h, char *title, int pfps, int fps) {
|
|||||||
//
|
//
|
||||||
// Adds an entity to the game.
|
// Adds an entity to the game.
|
||||||
void GameLib_AddEntity(Entity e) {
|
void GameLib_AddEntity(Entity e) {
|
||||||
if (_n_entities >= _n_entities_res) {
|
if (g_NumEntities >= g_NumEntitiesAllocated) {
|
||||||
Entity *entity_aux;
|
Entity *entity_aux;
|
||||||
int *entity_flag_aux;
|
int *entity_flag_aux;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// Grow the array
|
// Grow the array
|
||||||
if (_n_entities_res == 0)
|
if (g_NumEntitiesAllocated == 0) {
|
||||||
_n_entities_res = 32;
|
g_NumEntitiesAllocated = 32;
|
||||||
else
|
} else {
|
||||||
_n_entities_res *= 2;
|
g_NumEntitiesAllocated *= 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) {
|
entity_aux = malloc(sizeof(Entity) * g_NumEntitiesAllocated);
|
||||||
free(_entity);
|
entity_flag_aux = malloc(sizeof(int) * g_NumEntitiesAllocated);
|
||||||
free(_entity_flag);
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
|
entity_aux[i] = g_Entity[i];
|
||||||
|
entity_flag_aux[i] = g_EntityFlag[i];
|
||||||
}
|
}
|
||||||
_entity = entity_aux;
|
if (g_Entity) {
|
||||||
_entity_flag = entity_flag_aux;
|
free(g_Entity);
|
||||||
|
free(g_EntityFlag);
|
||||||
|
}
|
||||||
|
g_Entity = entity_aux;
|
||||||
|
g_EntityFlag = entity_flag_aux;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the entity
|
// Add the entity
|
||||||
_entity[_n_entities] = e;
|
g_Entity[g_NumEntities] = e;
|
||||||
_entity_flag[_n_entities] = 1;
|
g_EntityFlag[g_NumEntities] = 1;
|
||||||
_n_entities++;
|
g_NumEntities++;
|
||||||
|
|
||||||
// Mark for light update
|
// Mark for light update
|
||||||
Entity_MarkUpdateLight(e, _entity, _n_entities);
|
Entity_MarkUpdateLight(e, g_Entity, g_NumEntities);
|
||||||
|
|
||||||
Entity_CalcBBox(e);
|
Entity_CalcBBox(e);
|
||||||
|
|
||||||
@@ -128,19 +118,19 @@ void GameLib_AddEntity(Entity e) {
|
|||||||
// removes the reference to the entity.
|
// removes the reference to the entity.
|
||||||
int GameLib_UnrefEntity(Entity e) {
|
int GameLib_UnrefEntity(Entity e) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
if (e == _entity[i]) {
|
if (e == g_Entity[i]) {
|
||||||
// Mark or unref
|
// Mark or unref
|
||||||
if (_entities_lock) {
|
if (g_EntitiesLock) {
|
||||||
_entity_flag[i] = -2;
|
g_EntityFlag[i] = -2;
|
||||||
} else {
|
} else {
|
||||||
_entity[i] = NULL;
|
g_Entity[i] = NULL;
|
||||||
_entity_flag[i] = 0;
|
g_EntityFlag[i] = 0;
|
||||||
}
|
}
|
||||||
_entities_compactate = 1;
|
g_EntitiesCompactate = 1;
|
||||||
|
|
||||||
// Mark for light update
|
// Mark for light update
|
||||||
Entity_MarkUpdateLight(e, _entity, _n_entities);
|
Entity_MarkUpdateLight(e, g_Entity, g_NumEntities);
|
||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,10 +146,10 @@ int GameLib_DelEntity(Entity e) {
|
|||||||
if ((i = GameLib_UnrefEntity(e)) == -1) {
|
if ((i = GameLib_UnrefEntity(e)) == -1) {
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (_entities_lock) {
|
if (g_EntitiesLock) {
|
||||||
// Delete latter
|
// Delete latter
|
||||||
_entity[i] = e;
|
g_Entity[i] = e;
|
||||||
_entity_flag[i] = -1;
|
g_EntityFlag[i] = -1;
|
||||||
} else {
|
} else {
|
||||||
// Delete now
|
// Delete now
|
||||||
Entity_Destroy(e);
|
Entity_Destroy(e);
|
||||||
@@ -174,23 +164,25 @@ int GameLib_DelEntity(Entity e) {
|
|||||||
void GameLib_Compactate() {
|
void GameLib_Compactate() {
|
||||||
int i, j;
|
int i, j;
|
||||||
j = 0;
|
j = 0;
|
||||||
if (!_entities_compactate)
|
if (!g_EntitiesCompactate) {
|
||||||
return;
|
return;
|
||||||
for (i = 0; i < _n_entities; i++) {
|
}
|
||||||
if (!_entity[i] || _entity_flag[i] == -2)
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
|
if (!g_Entity[i] || g_EntityFlag[i] == -2) {
|
||||||
continue;
|
continue;
|
||||||
if (_entity_flag[i] == -1) {
|
}
|
||||||
Entity_Destroy(_entity[i]);
|
if (g_EntityFlag[i] == -1) {
|
||||||
|
Entity_Destroy(g_Entity[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i > j) {
|
if (i > j) {
|
||||||
_entity[j] = _entity[i];
|
g_Entity[j] = g_Entity[i];
|
||||||
_entity_flag[j] = _entity_flag[i];
|
g_EntityFlag[j] = g_EntityFlag[i];
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
_n_entities = j;
|
g_NumEntities = j;
|
||||||
_entities_compactate = 0;
|
g_EntitiesCompactate = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -203,45 +195,47 @@ void GameLib_ProcLoop(void *data) {
|
|||||||
long long time;
|
long long time;
|
||||||
|
|
||||||
// Step the gamePosition
|
// Step the gamePosition
|
||||||
_game_pos0[0] = _game_pos1[0] + _game_posOffset[0];
|
g_GamePos0[0] = g_GamePos1[0] + g_GamePosOffset[0];
|
||||||
_game_pos0[1] = _game_pos1[1] + _game_posOffset[1];
|
g_GamePos0[1] = g_GamePos1[1] + g_GamePosOffset[1];
|
||||||
|
|
||||||
// Process
|
// Process
|
||||||
time = Time_GetTime();
|
time = Time_GetTime();
|
||||||
_entities_lock = 1;
|
g_EntitiesLock = 1;
|
||||||
if (_gameproc) {
|
if (g_GameProcFunc) {
|
||||||
_gameproc();
|
g_GameProcFunc();
|
||||||
}
|
}
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
if (!_entity[i])
|
if (!g_Entity[i]) {
|
||||||
continue;
|
continue;
|
||||||
Entity_Process(_entity[i], _pft);
|
}
|
||||||
|
Entity_Process(g_Entity[i], g_ProcFt);
|
||||||
}
|
}
|
||||||
GameLib_Compactate();
|
GameLib_Compactate();
|
||||||
_entities_lock = 0;
|
g_EntitiesLock = 0;
|
||||||
t_proc += Time_GetTime() - time;
|
t_proc += Time_GetTime() - time;
|
||||||
|
|
||||||
// Colisions between entities
|
// Collisions between entities
|
||||||
time = Time_GetTime();
|
time = Time_GetTime();
|
||||||
_entities_lock = 1;
|
g_EntitiesLock = 1;
|
||||||
count = 0;
|
count = 0;
|
||||||
do {
|
do {
|
||||||
repeat = 0;
|
repeat = 0;
|
||||||
CollisionInfo collInfo = NULL;
|
CollisionInfo collInfo = NULL;
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
if (!(_entity[i]->flags & EntityFlag_Collision) || _entity[i]->mass < 0.0f)
|
if (!(g_Entity[i]->flags & EntityFlag_Collision) || g_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) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (j = 0; j < _n_entities; j++) {
|
if (g_Entity[i]->vel[0] <= 0.0f && g_Entity[i]->vel[0] >= -0.0f && g_Entity[i]->vel[1] <= 0.0f &&
|
||||||
if (i == j || !(_entity[j]->flags & EntityFlag_Collision) ||
|
g_Entity[i]->vel[1] >= -0.0f) {
|
||||||
CollisionInfo_CheckRepetition(collInfo, _entity[i], _entity[j]) ||
|
|
||||||
!Entity_BBoxIntersect(_entity[i], _entity[j])) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Entity_CheckCollision(_entity[i], _entity[j], &collInfo);
|
for (j = 0; j < g_NumEntities; j++) {
|
||||||
|
if (i == j || !(g_Entity[j]->flags & EntityFlag_Collision) ||
|
||||||
|
CollisionInfo_CheckRepetition(collInfo, g_Entity[i], g_Entity[j]) ||
|
||||||
|
!Entity_BBoxIntersect(g_Entity[i], g_Entity[j])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Entity_CheckCollision(g_Entity[i], g_Entity[j], &collInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Entity_CollisionInfoResponse(collInfo)) {
|
if (Entity_CollisionInfoResponse(collInfo)) {
|
||||||
@@ -253,51 +247,54 @@ void GameLib_ProcLoop(void *data) {
|
|||||||
|
|
||||||
// Stop remaining collisions
|
// Stop remaining collisions
|
||||||
if (count == 10) {
|
if (count == 10) {
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
if (!(_entity[i]->flags & EntityFlag_Collision) || _entity[i]->mass < 0.0f)
|
if (!(g_Entity[i]->flags & EntityFlag_Collision) || g_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])) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Entity_CheckCollision(_entity[i], _entity[j], NULL)) {
|
for (j = 0; j < g_NumEntities; j++) {
|
||||||
vec2_set(_entity[i]->vel, 0, 0);
|
if (i == j || !(g_Entity[j]->flags & EntityFlag_Collision) ||
|
||||||
Entity_CalcBBox(_entity[i]);
|
!Entity_BBoxIntersect(g_Entity[i], g_Entity[j])) {
|
||||||
vec2_set(_entity[j]->vel, 0, 0);
|
continue;
|
||||||
Entity_CalcBBox(_entity[j]);
|
}
|
||||||
|
if (Entity_CheckCollision(g_Entity[i], g_Entity[j], NULL)) {
|
||||||
|
vec2_set(g_Entity[i]->vel, 0, 0);
|
||||||
|
Entity_CalcBBox(g_Entity[i]);
|
||||||
|
vec2_set(g_Entity[j]->vel, 0, 0);
|
||||||
|
Entity_CalcBBox(g_Entity[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GameLib_Compactate();
|
GameLib_Compactate();
|
||||||
_entities_lock = 0;
|
g_EntitiesLock = 0;
|
||||||
t_col += Time_GetTime() - time;
|
t_col += Time_GetTime() - time;
|
||||||
|
|
||||||
// Process Overlaps
|
// Process Overlaps
|
||||||
time = Time_GetTime();
|
time = Time_GetTime();
|
||||||
_entities_lock = 1;
|
g_EntitiesLock = 1;
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
if (!(_entity[i]->flags & EntityFlag_Overlap) || _entity[i]->mass < 0.0f)
|
if (!(g_Entity[i]->flags & EntityFlag_Overlap) || g_Entity[i]->mass < 0.0f) {
|
||||||
continue;
|
continue;
|
||||||
for (j = 0; j < _n_entities; j++) {
|
}
|
||||||
if (!(_entity[j]->flags & EntityFlag_Overlap) || i == j)
|
for (j = 0; j < g_NumEntities; j++) {
|
||||||
|
if (!(g_Entity[j]->flags & EntityFlag_Overlap) || i == j) {
|
||||||
continue;
|
continue;
|
||||||
Entity_Overlaps(_entity[i], _entity[j]);
|
}
|
||||||
|
Entity_Overlaps(g_Entity[i], g_Entity[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GameLib_Compactate();
|
GameLib_Compactate();
|
||||||
_entities_lock = 0;
|
g_EntitiesLock = 0;
|
||||||
t_over += Time_GetTime() - time;
|
t_over += Time_GetTime() - time;
|
||||||
|
|
||||||
// Sort
|
// Sort
|
||||||
int n, n2, swap;
|
int n, n2, swap;
|
||||||
n = _n_entities;
|
n = g_NumEntities;
|
||||||
do {
|
do {
|
||||||
n2 = 0;
|
n2 = 0;
|
||||||
for (i = 1; i < n; i++) {
|
for (i = 1; i < n; i++) {
|
||||||
Entity ent1 = _entity[i - 1];
|
Entity ent1 = g_Entity[i - 1];
|
||||||
Entity ent2 = _entity[i];
|
Entity ent2 = g_Entity[i];
|
||||||
swap = 0;
|
swap = 0;
|
||||||
if (ent1->zorder > ent2->zorder) {
|
if (ent1->zorder > ent2->zorder) {
|
||||||
// Lower level
|
// Lower level
|
||||||
@@ -318,9 +315,9 @@ void GameLib_ProcLoop(void *data) {
|
|||||||
}
|
}
|
||||||
if (swap) {
|
if (swap) {
|
||||||
Entity ent;
|
Entity ent;
|
||||||
ent = _entity[i];
|
ent = g_Entity[i];
|
||||||
_entity[i] = _entity[i - 1];
|
g_Entity[i] = g_Entity[i - 1];
|
||||||
_entity[i - 1] = ent;
|
g_Entity[i - 1] = ent;
|
||||||
n2 = i;
|
n2 = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,18 +326,18 @@ void GameLib_ProcLoop(void *data) {
|
|||||||
|
|
||||||
// PostProcess
|
// PostProcess
|
||||||
time = Time_GetTime();
|
time = Time_GetTime();
|
||||||
_entities_lock = 1;
|
g_EntitiesLock = 1;
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
Entity_PostProcess(_entity[i], _pft);
|
Entity_PostProcess(g_Entity[i], g_ProcFt);
|
||||||
if (Entity_IsMoving(_entity[i])) {
|
if (Entity_IsMoving(g_Entity[i])) {
|
||||||
Entity_MarkUpdateLight(_entity[i], _entity, _n_entities);
|
Entity_MarkUpdateLight(g_Entity[i], g_Entity, g_NumEntities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_gamepostproc) {
|
if (g_GamePostProcFunc) {
|
||||||
_gamepostproc();
|
g_GamePostProcFunc();
|
||||||
}
|
}
|
||||||
GameLib_Compactate();
|
GameLib_Compactate();
|
||||||
_entities_lock = 0;
|
g_EntitiesLock = 0;
|
||||||
t_postproc += Time_GetTime() - time;
|
t_postproc += Time_GetTime() - time;
|
||||||
|
|
||||||
fproc_count++;
|
fproc_count++;
|
||||||
@@ -360,50 +357,50 @@ void GameLib_DrawLoop(void *data, float f) {
|
|||||||
time = Time_GetTime();
|
time = Time_GetTime();
|
||||||
|
|
||||||
// PreDraw
|
// PreDraw
|
||||||
if (_gamepredraw) {
|
if (g_GamePreDrawFunc) {
|
||||||
_gamepredraw(f);
|
g_GamePreDrawFunc(f);
|
||||||
} else {
|
} else {
|
||||||
if (_nParallaxBackgrounds == 0) {
|
if (g_NumParallaxBackgrounds == 0) {
|
||||||
// Clean screen
|
// Clean screen
|
||||||
Draw_Clean(0, 0, 0);
|
Draw_Clean(0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw parallax backgrounds
|
// Draw parallax backgrounds
|
||||||
for (i = 0; i < _nParallaxBackgrounds; i++) {
|
for (i = 0; i < g_NumParallaxBackgrounds; i++) {
|
||||||
Draw_ImgParallax(
|
Draw_ImgParallax(
|
||||||
_parallaxBackground[i].img,
|
g_ParallaxBackground[i].img,
|
||||||
_parallaxBackground[i].imgSize,
|
g_ParallaxBackground[i].imgSize,
|
||||||
_parallaxBackground[i].imgOffset,
|
g_ParallaxBackground[i].imgOffset,
|
||||||
_parallaxBackground[i].parallaxFactor,
|
g_ParallaxBackground[i].parallaxFactor,
|
||||||
game_pos,
|
game_pos,
|
||||||
_game_size);
|
g_GameSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw entities
|
// Draw entities
|
||||||
GameLib_Compactate();
|
GameLib_Compactate();
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
Entity e = _entity[i];
|
Entity e = g_Entity[i];
|
||||||
|
|
||||||
// Check visivility
|
// Check visibility
|
||||||
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], g_GameSize[0], g_GameSize[1])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update ilumination of this entity
|
// Update illumination of this entity
|
||||||
if (Entity_IsUpdateLight(e)) {
|
if (Entity_IsUpdateLight(e)) {
|
||||||
Entity_Iluminate(e, _entity, _n_entities);
|
Entity_Iluminate(e, g_Entity, g_NumEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
Draw_SetColor(1, 1, 1, 1);
|
||||||
_entities_lock = 1;
|
g_EntitiesLock = 1;
|
||||||
if (_gamedraw) {
|
if (g_GameDrawFunc) {
|
||||||
_gamedraw(f);
|
g_GameDrawFunc(f);
|
||||||
}
|
}
|
||||||
GameLib_Compactate();
|
GameLib_Compactate();
|
||||||
_entities_lock = 0;
|
g_EntitiesLock = 0;
|
||||||
|
|
||||||
t_draw += Time_GetTime() - time;
|
t_draw += Time_GetTime() - time;
|
||||||
|
|
||||||
@@ -418,7 +415,7 @@ void GameLib_DrawLoop(void *data, float f) {
|
|||||||
idx++;
|
idx++;
|
||||||
snprintf(strFile, 255, "shot-%04d.png", idx);
|
snprintf(strFile, 255, "shot-%04d.png", idx);
|
||||||
} while (access(strFile, F_OK) != -1);
|
} while (access(strFile, F_OK) != -1);
|
||||||
Draw_SaveScreenshoot(strFile);
|
Draw_SaveScreenshot(strFile);
|
||||||
Print("Screenshot saved \"%s\"\n", strFile);
|
Print("Screenshot saved \"%s\"\n", strFile);
|
||||||
}
|
}
|
||||||
#endif // EMSCRIPTEN
|
#endif // EMSCRIPTEN
|
||||||
@@ -430,7 +427,7 @@ void GameLib_DrawLoop(void *data, float f) {
|
|||||||
Print("t_over.....:%6lldus\n", t_over / fproc_count);
|
Print("t_over.....:%6lldus\n", t_over / fproc_count);
|
||||||
Print("t_postproc.:%6lldus\n", t_postproc / fproc_count);
|
Print("t_postproc.:%6lldus\n", t_postproc / fproc_count);
|
||||||
Print("t_draw.....:%6lldus\n", t_draw / fdraw_count);
|
Print("t_draw.....:%6lldus\n", t_draw / fdraw_count);
|
||||||
Print("n_ents.....:%6lld\n", _n_entities);
|
Print("n_ents.....:%6lld\n", g_NumEntities);
|
||||||
t_proc = 0;
|
t_proc = 0;
|
||||||
t_col = 0;
|
t_col = 0;
|
||||||
t_over = 0;
|
t_over = 0;
|
||||||
@@ -446,10 +443,10 @@ void GameLib_DrawLoop(void *data, float f) {
|
|||||||
//
|
//
|
||||||
// Loops the game.
|
// 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;
|
g_GameProcFunc = gameproc;
|
||||||
_gamepostproc = gamepostproc;
|
g_GamePostProcFunc = gamepostproc;
|
||||||
_gamepredraw = gamepredraw;
|
g_GamePreDrawFunc = gamepredraw;
|
||||||
_gamedraw = gamedraw;
|
g_GameDrawFunc = gamedraw;
|
||||||
t_proc = 0;
|
t_proc = 0;
|
||||||
t_col = 0;
|
t_col = 0;
|
||||||
t_over = 0;
|
t_over = 0;
|
||||||
@@ -470,30 +467,30 @@ void GameLib_Loop(void (*gameproc)(), void (*gamepostproc)(), void (*gamepredraw
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
void GameLib_GetPos(int pos[2]) {
|
void GameLib_GetPos(int pos[2]) {
|
||||||
pos[0] = _game_pos1[0];
|
pos[0] = g_GamePos1[0];
|
||||||
pos[1] = _game_pos1[1];
|
pos[1] = g_GamePos1[1];
|
||||||
}
|
}
|
||||||
void GameLib_SetPos(int pos[2]) {
|
void GameLib_SetPos(const int pos[2]) {
|
||||||
_game_pos0[0] = pos[0];
|
g_GamePos0[0] = pos[0];
|
||||||
_game_pos0[1] = pos[1];
|
g_GamePos0[1] = pos[1];
|
||||||
_game_pos1[0] = pos[0];
|
g_GamePos1[0] = pos[0];
|
||||||
_game_pos1[1] = pos[1];
|
g_GamePos1[1] = pos[1];
|
||||||
}
|
}
|
||||||
void GameLib_UpdatePos(int pos[2]) {
|
void GameLib_UpdatePos(const int pos[2]) {
|
||||||
_game_pos1[0] = pos[0];
|
g_GamePos1[0] = pos[0];
|
||||||
_game_pos1[1] = pos[1];
|
g_GamePos1[1] = pos[1];
|
||||||
}
|
}
|
||||||
void GameLib_GetSize(int size[2]) {
|
void GameLib_GetSize(int size[2]) {
|
||||||
size[0] = _game_size[0];
|
size[0] = g_GameSize[0];
|
||||||
size[1] = _game_size[1];
|
size[1] = g_GameSize[1];
|
||||||
}
|
}
|
||||||
void GameLib_GetPosInstant(int pos[2], float f) {
|
void GameLib_GetPosInstant(int pos[2], float f) {
|
||||||
pos[0] = _game_pos0[0] + f * ((_game_pos1[0] + _game_posOffset[0]) - _game_pos0[0]);
|
pos[0] = g_GamePos0[0] + f * ((g_GamePos1[0] + g_GamePosOffset[0]) - g_GamePos0[0]);
|
||||||
pos[1] = _game_pos0[1] + f * ((_game_pos1[1] + _game_posOffset[1]) - _game_pos0[1]);
|
pos[1] = g_GamePos0[1] + f * ((g_GamePos1[1] + g_GamePosOffset[1]) - g_GamePos0[1]);
|
||||||
}
|
}
|
||||||
void GameLib_SetPosOffset(int posOffset[2]) {
|
void GameLib_SetPosOffset(const int posOffset[2]) {
|
||||||
_game_posOffset[0] = posOffset[0];
|
g_GamePosOffset[0] = posOffset[0];
|
||||||
_game_posOffset[1] = posOffset[1];
|
g_GamePosOffset[1] = posOffset[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -506,11 +503,11 @@ void GameLib_MoveToPos(vec2 pos, float f) {
|
|||||||
GameLib_MoveToPosH(pos, f);
|
GameLib_MoveToPosH(pos, f);
|
||||||
GameLib_MoveToPosV(pos, f);
|
GameLib_MoveToPosV(pos, f);
|
||||||
}
|
}
|
||||||
void GameLib_MoveToPosH(vec2 pos, float f) {
|
void GameLib_MoveToPosH(const vec2 pos, float f) {
|
||||||
_game_pos1[0] = _game_pos1[0] + (pos[0] - (_game_pos1[0] + (_game_size[0] / 2.0f))) * f;
|
g_GamePos1[0] = g_GamePos1[0] + (pos[0] - (g_GamePos1[0] + (g_GameSize[0] / 2.0f))) * f;
|
||||||
}
|
}
|
||||||
void GameLib_MoveToPosV(vec2 pos, float f) {
|
void GameLib_MoveToPosV(const vec2 pos, float f) {
|
||||||
_game_pos1[1] = _game_pos1[1] + (pos[1] - (_game_pos1[1] + (_game_size[1] / 2.0f))) * f;
|
g_GamePos1[1] = g_GamePos1[1] + (pos[1] - (g_GamePos1[1] + (g_GameSize[1] / 2.0f))) * f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -520,12 +517,13 @@ void GameLib_MoveToPosV(vec2 pos, float f) {
|
|||||||
void GameLib_DelEnts() {
|
void GameLib_DelEnts() {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
if (!_entity[i])
|
if (!g_Entity[i]) {
|
||||||
continue;
|
continue;
|
||||||
Entity_Destroy(_entity[i]);
|
|
||||||
}
|
}
|
||||||
_n_entities = 0;
|
Entity_Destroy(g_Entity[i]);
|
||||||
|
}
|
||||||
|
g_NumEntities = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -534,10 +532,11 @@ void GameLib_DelEnts() {
|
|||||||
// Iterates every entity.
|
// Iterates every entity.
|
||||||
void GameLib_ForEachEnt(int (*func)(Entity ent)) {
|
void GameLib_ForEachEnt(int (*func)(Entity ent)) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
if (!_entity[i])
|
if (!g_Entity[i]) {
|
||||||
continue;
|
continue;
|
||||||
if (!func(_entity[i])) {
|
}
|
||||||
|
if (!func(g_Entity[i])) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -550,11 +549,12 @@ void GameLib_ForEachEnt(int (*func)(Entity ent)) {
|
|||||||
Entity GameLib_SearchEnt(int (*func)(Entity ent, void *d), void *d) {
|
Entity GameLib_SearchEnt(int (*func)(Entity ent, void *d), void *d) {
|
||||||
int i;
|
int i;
|
||||||
Entity ent = NULL;
|
Entity ent = NULL;
|
||||||
for (i = 0; i < _n_entities; i++) {
|
for (i = 0; i < g_NumEntities; i++) {
|
||||||
if (!_entity[i])
|
if (!g_Entity[i]) {
|
||||||
continue;
|
continue;
|
||||||
if (func(_entity[i], d)) {
|
}
|
||||||
ent = _entity[i];
|
if (func(g_Entity[i], d)) {
|
||||||
|
ent = g_Entity[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -575,11 +575,11 @@ int GameLib_EntityCustomCheckCollision(Entity ent, vec2 vel) {
|
|||||||
vec2_copy(ent->vel, vel);
|
vec2_copy(ent->vel, vel);
|
||||||
Entity_CalcBBox(ent);
|
Entity_CalcBBox(ent);
|
||||||
|
|
||||||
for (j = 0; j < _n_entities; j++) {
|
for (j = 0; j < g_NumEntities; j++) {
|
||||||
if (!(_entity[j]->flags & EntityFlag_Collision) || !Entity_BBoxIntersect(ent, _entity[j])) {
|
if (!(g_Entity[j]->flags & EntityFlag_Collision) || !Entity_BBoxIntersect(ent, g_Entity[j])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Entity_CheckCollision(ent, _entity[j], &collInfo);
|
Entity_CheckCollision(ent, g_Entity[j], &collInfo);
|
||||||
if (collInfo != NULL) {
|
if (collInfo != NULL) {
|
||||||
collision = 1;
|
collision = 1;
|
||||||
break;
|
break;
|
||||||
@@ -598,16 +598,16 @@ int GameLib_EntityCustomCheckCollision(Entity ent, vec2 vel) {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
void GameLib_PlaySound(AudioSnd snd, int x, int y) {
|
void GameLib_PlaySound(AudioSnd snd, int x, int y) {
|
||||||
float vleft, vright, dx, dy;
|
float vLeft, vRight, dx, dy;
|
||||||
int r, cx, cy, off;
|
int r, cx, cy, off;
|
||||||
|
|
||||||
// Get the screen context
|
// Get the screen context
|
||||||
cx = _game_pos1[0] + _game_size[0] / 2;
|
cx = g_GamePos1[0] + g_GameSize[0] / 2;
|
||||||
cy = _game_pos1[1] + _game_size[1] / 2;
|
cy = g_GamePos1[1] + g_GameSize[1] / 2;
|
||||||
if (_game_size[0] > _game_size[1]) {
|
if (g_GameSize[0] > g_GameSize[1]) {
|
||||||
r = _game_size[0] / 2;
|
r = g_GameSize[0] / 2;
|
||||||
} else {
|
} else {
|
||||||
r = _game_size[1] / 2;
|
r = g_GameSize[1] / 2;
|
||||||
}
|
}
|
||||||
r = r * 1.2f;
|
r = r * 1.2f;
|
||||||
off = r / 10.0f;
|
off = r / 10.0f;
|
||||||
@@ -615,22 +615,24 @@ void GameLib_PlaySound(AudioSnd snd, int x, int y) {
|
|||||||
// Calculate volumes
|
// Calculate volumes
|
||||||
dx = x - (cx + off);
|
dx = x - (cx + off);
|
||||||
dy = y - (cy);
|
dy = y - (cy);
|
||||||
vright = 1.0f - (sqrtf(dx * dx + dy * dy) / (float)r);
|
vRight = 1.0f - (sqrtf(dx * dx + dy * dy) / (float)r);
|
||||||
dx = x - (cx - off);
|
dx = x - (cx - off);
|
||||||
dy = y - (cy);
|
dy = y - (cy);
|
||||||
vleft = 1.0f - (sqrtf(dx * dx + dy * dy) / (float)r);
|
vLeft = 1.0f - (sqrtf(dx * dx + dy * dy) / (float)r);
|
||||||
|
|
||||||
// Clamp to 0
|
// Clamp to 0
|
||||||
if (vleft < 0.0f)
|
if (vLeft < 0.0f) {
|
||||||
vleft = 0.0f;
|
vLeft = 0.0f;
|
||||||
if (vright < 0.0f)
|
}
|
||||||
vright = 0.0f;
|
if (vRight < 0.0f) {
|
||||||
if (vleft <= 0.0f && vright <= 0.0f) {
|
vRight = 0.0f;
|
||||||
|
}
|
||||||
|
if (vLeft <= 0.0f && vRight <= 0.0f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PLAY!
|
// PLAY!
|
||||||
Audio_PlaySound(snd, vleft, vright, 0);
|
Audio_PlaySound(snd, vLeft, vRight, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -648,9 +650,9 @@ AudioChn GameLib_PlayLoopingSound(AudioSnd snd) {
|
|||||||
//
|
//
|
||||||
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) {
|
||||||
if (Entity_IsLight(e)) {
|
if (Entity_IsLight(e)) {
|
||||||
Entity_MarkUpdateLight(e, _entity, _n_entities);
|
Entity_MarkUpdateLight(e, g_Entity, g_NumEntities);
|
||||||
Entity_SetLight(e, r, g, b, rad);
|
Entity_SetLight(e, r, g, b, rad);
|
||||||
Entity_MarkUpdateLight(e, _entity, _n_entities);
|
Entity_MarkUpdateLight(e, g_Entity, g_NumEntities);
|
||||||
} else {
|
} else {
|
||||||
Entity_SetLight(e, r, g, b, rad);
|
Entity_SetLight(e, r, g, b, rad);
|
||||||
}
|
}
|
||||||
@@ -663,11 +665,11 @@ void GameLib_EntitySetLight(Entity e, float r, float g, float b, float rad) {
|
|||||||
void GameLib_ConvertScreenPositionToGamePosition(vec2 screenPos, vec2 gamePos, float f) {
|
void GameLib_ConvertScreenPositionToGamePosition(vec2 screenPos, vec2 gamePos, float f) {
|
||||||
int game_pos[2];
|
int game_pos[2];
|
||||||
|
|
||||||
game_pos[0] = _game_pos0[0] + f * ((_game_pos1[0] + _game_posOffset[0]) - _game_pos0[0]);
|
game_pos[0] = g_GamePos0[0] + f * ((g_GamePos1[0] + g_GamePosOffset[0]) - g_GamePos0[0]);
|
||||||
game_pos[1] = _game_pos0[1] + f * ((_game_pos1[1] + _game_posOffset[1]) - _game_pos0[1]);
|
game_pos[1] = g_GamePos0[1] + f * ((g_GamePos1[1] + g_GamePosOffset[1]) - g_GamePos0[1]);
|
||||||
|
|
||||||
gamePos[0] = (screenPos[0] * _game_size[0]) + game_pos[0];
|
gamePos[0] = (screenPos[0] * g_GameSize[0]) + game_pos[0];
|
||||||
gamePos[1] = (screenPos[1] * _game_size[1]) + game_pos[1];
|
gamePos[1] = (screenPos[1] * g_GameSize[1]) + game_pos[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -675,23 +677,23 @@ void GameLib_ConvertScreenPositionToGamePosition(vec2 screenPos, vec2 gamePos, f
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
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;
|
int idx = g_NumParallaxBackgrounds;
|
||||||
if ((idx + 1) >= MaxParallaxBackgrounds) {
|
if ((idx + 1) >= MaxParallaxBackgrounds) {
|
||||||
Print("GameLib: Can't add parallaxBackground, limit reached.");
|
Print("GameLib: Can't add parallaxBackground, limit reached.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_parallaxBackground[idx].img = img;
|
g_ParallaxBackground[idx].img = img;
|
||||||
_parallaxBackground[idx].imgSize[0] = imgSize[0];
|
g_ParallaxBackground[idx].imgSize[0] = imgSize[0];
|
||||||
_parallaxBackground[idx].imgSize[1] = imgSize[1];
|
g_ParallaxBackground[idx].imgSize[1] = imgSize[1];
|
||||||
_parallaxBackground[idx].imgOffset[0] = imgOffset[0];
|
g_ParallaxBackground[idx].imgOffset[0] = imgOffset[0];
|
||||||
_parallaxBackground[idx].imgOffset[1] = imgOffset[1];
|
g_ParallaxBackground[idx].imgOffset[1] = imgOffset[1];
|
||||||
_parallaxBackground[idx].parallaxFactor[0] = parallaxFactor[0];
|
g_ParallaxBackground[idx].parallaxFactor[0] = parallaxFactor[0];
|
||||||
_parallaxBackground[idx].parallaxFactor[1] = parallaxFactor[1];
|
g_ParallaxBackground[idx].parallaxFactor[1] = parallaxFactor[1];
|
||||||
_nParallaxBackgrounds++;
|
g_NumParallaxBackgrounds++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// GameLib_CleanParallaxBackgrounds
|
// GameLib_CleanParallaxBackgrounds
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
void GameLib_CleanParallaxBackgrounds() { _nParallaxBackgrounds = 0; }
|
void GameLib_CleanParallaxBackgrounds() { g_NumParallaxBackgrounds = 0; }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _GAMELIB_H_
|
#ifndef GameLib_H
|
||||||
#define _GAMELIB_H_
|
#define GameLib_H
|
||||||
|
|
||||||
#include "Anim.h"
|
#include "Anim.h"
|
||||||
#include "Audio.h"
|
#include "Audio.h"
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
// GameLib_Init
|
// GameLib_Init
|
||||||
//
|
//
|
||||||
// Initializes the game.
|
// 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
|
// GameLib_AddEntity
|
||||||
@@ -51,11 +51,11 @@ void GameLib_Loop(void (*gameproc)(), void (*gamepostproc)(), void (*gamepredraw
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
void GameLib_GetPos(int pos[2]);
|
void GameLib_GetPos(int pos[2]);
|
||||||
void GameLib_SetPos(int pos[2]);
|
void GameLib_SetPos(const int pos[2]);
|
||||||
void GameLib_UpdatePos(int pos[2]);
|
void GameLib_UpdatePos(const int pos[2]);
|
||||||
void GameLib_GetSize(int size[2]);
|
void GameLib_GetSize(int size[2]);
|
||||||
void GameLib_GetPosInstant(int pos[2], float f);
|
void GameLib_GetPosInstant(int pos[2], float f);
|
||||||
void GameLib_SetPosOffset(int posOffset[2]);
|
void GameLib_SetPosOffset(const int posOffset[2]);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// GameLib_MoveToPos
|
// GameLib_MoveToPos
|
||||||
@@ -64,8 +64,8 @@ void GameLib_SetPosOffset(int posOffset[2]);
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
void GameLib_MoveToPos(vec2 pos, float f);
|
void GameLib_MoveToPos(vec2 pos, float f);
|
||||||
void GameLib_MoveToPosH(vec2 pos, float f);
|
void GameLib_MoveToPosH(const vec2 pos, float f);
|
||||||
void GameLib_MoveToPosV(vec2 pos, float f);
|
void GameLib_MoveToPosV(const vec2 pos, float f);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// GameLib_ForEachEn
|
// GameLib_ForEachEn
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -158,13 +158,13 @@ int Input_GetDir(vec2 dir) {
|
|||||||
Uint8 buttons;
|
Uint8 buttons;
|
||||||
int mx, my;
|
int mx, my;
|
||||||
float dlen;
|
float dlen;
|
||||||
extern int _width, _height;
|
extern int g_Width, g_Height;
|
||||||
|
|
||||||
// Get mouse state
|
// Get mouse state
|
||||||
buttons = SDL_GetMouseState(&mx, &my);
|
buttons = SDL_GetMouseState(&mx, &my);
|
||||||
if (buttons) {
|
if (buttons) {
|
||||||
// Use the mouse
|
// Use the mouse
|
||||||
vec2_set(dir, mx - (_width / 2), my - (_height / 2.0f));
|
vec2_set(dir, mx - (g_Width / 2), my - (g_Height / 2.0f));
|
||||||
dlen = 1.0f / sqrtf(vec2_dot(dir, dir));
|
dlen = 1.0f / sqrtf(vec2_dot(dir, dir));
|
||||||
vec2_scale(dir, dir, dlen);
|
vec2_scale(dir, dir, dlen);
|
||||||
return (1);
|
return (1);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _INPUT_H_
|
#ifndef Input_H
|
||||||
#define _INPUT_H_
|
#define Input_H
|
||||||
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright (C) 2013 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2013-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -19,10 +18,12 @@ QuadArray2D QuadArray2D_Create(int resVertex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QuadArray2D_Destroy(QuadArray2D *quadArray) {
|
void QuadArray2D_Destroy(QuadArray2D *quadArray) {
|
||||||
if (!quadArray)
|
if (!quadArray) {
|
||||||
return;
|
return;
|
||||||
if (!quadArray[0])
|
}
|
||||||
|
if (!quadArray[0]) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
free(quadArray[0]->vertexData);
|
free(quadArray[0]->vertexData);
|
||||||
free(quadArray[0]);
|
free(quadArray[0]);
|
||||||
@@ -48,7 +49,7 @@ void QuadArray2D_AddVertex(QuadArray2D quadArray, float v[]) {
|
|||||||
|
|
||||||
void QuadArray2D_AddQuad(
|
void QuadArray2D_AddQuad(
|
||||||
QuadArray2D quadArray, float x0, float y0, float u0, float v0, float x1, float y1, float u1, float v1,
|
QuadArray2D quadArray, float x0, float y0, float u0, float v0, float x1, float y1, float u1, float v1,
|
||||||
float color[]) {
|
const float color[]) {
|
||||||
float v[Vertex2D_Length];
|
float v[Vertex2D_Length];
|
||||||
|
|
||||||
// Set the color
|
// Set the color
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2013 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2013-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _QUADARRAY2D_H_
|
#ifndef QuadArray2D_H
|
||||||
#define _QUADARRAY2D_H_
|
#define QuadArray2D_H
|
||||||
|
|
||||||
// Vertex2D -> (x,y) (u,v) (r,g,b,a)
|
// Vertex2D -> (x,y) (u,v) (r,g,b,a)
|
||||||
#define Vertex2D_Length 8
|
#define Vertex2D_Length 8
|
||||||
@@ -26,6 +26,6 @@ void QuadArray2D_AddVertex(QuadArray2D quadArray, float v[]);
|
|||||||
|
|
||||||
void QuadArray2D_AddQuad(
|
void QuadArray2D_AddQuad(
|
||||||
QuadArray2D quadArray, float x0, float y0, float u0, float v0, float x1, float y1, float u1, float v1,
|
QuadArray2D quadArray, float x0, float y0, float u0, float v0, float x1, float y1, float u1, float v1,
|
||||||
float color[]);
|
const float color[]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
// Copyright (C) 2011-2014 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "TimeUtils.h"
|
#include "TimeUtils.h"
|
||||||
@@ -53,10 +50,10 @@ long long Time_GetTime() {
|
|||||||
usecs = (t.tv_sec * 1000000ll) + (t.tv_usec);
|
usecs = (t.tv_sec * 1000000ll) + (t.tv_usec);
|
||||||
return (usecs);
|
return (usecs);
|
||||||
}
|
}
|
||||||
void Time_Pause(int pausa) {
|
void Time_Pause(long long pause) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = (long long)pausa / 1000000;
|
tv.tv_sec = (long long)pause / 1000000;
|
||||||
tv.tv_usec = (long long)pausa % 1000000;
|
tv.tv_usec = (long long)pause % 1000000;
|
||||||
select(0, NULL, NULL, NULL, &tv);
|
select(0, NULL, NULL, NULL, &tv);
|
||||||
}
|
}
|
||||||
#endif // if WIN32
|
#endif // if WIN32
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _TIME_H_
|
#ifndef TimeUtils_H
|
||||||
#define _TIME_H_
|
#define TimeUtils_H
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Time_GetTime
|
// Time_GetTime
|
||||||
@@ -13,6 +13,6 @@ long long Time_GetTime();
|
|||||||
// Time_Pause
|
// Time_Pause
|
||||||
//
|
//
|
||||||
// Pauses the execution for t usecs.
|
// Pauses the execution for t usecs.
|
||||||
void Time_Pause(int pausa);
|
void Time_Pause(long long pause);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
166
src/Util.c
166
src/Util.c
@@ -1,8 +1,7 @@
|
|||||||
// Copyright (C) 2011-2021 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
@@ -11,7 +10,7 @@
|
|||||||
// Misc
|
// Misc
|
||||||
//
|
//
|
||||||
|
|
||||||
float CosineInterpolation(float f) { return (1.0f - cos(f * Pi)) * 0.5f; }
|
float CosineInterpolation(float f) { return (1.0f - cosf(f * Pi)) * 0.5f; }
|
||||||
|
|
||||||
int MinimumInt(int i0, int i1) {
|
int MinimumInt(int i0, int i1) {
|
||||||
if (i1 < i0) {
|
if (i1 < i0) {
|
||||||
@@ -56,24 +55,24 @@ int Rect_PointInsideAny(TRect r[], int rCount, int x, int y) {
|
|||||||
// SolveQuadratic
|
// SolveQuadratic
|
||||||
//
|
//
|
||||||
// Solves a Quadratic equation using a, b and c coeficients.
|
// 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 root;
|
||||||
float divisor;
|
float divisor;
|
||||||
float b2;
|
float b2;
|
||||||
b2 = b * b;
|
b2 = b * b;
|
||||||
root = b2 - 4.0 * a * c;
|
root = b2 - 4.0f * a * c;
|
||||||
if (root < 0) {
|
if (root < 0) {
|
||||||
// Complex
|
// Complex
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
divisor = (2.0 * a);
|
divisor = (2.0f * a);
|
||||||
if (fabs(divisor) == 0.0f) {
|
if (fabsf(divisor) == 0.0f) {
|
||||||
// +inf -inf
|
// +inf -inf
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
root = sqrtf(root);
|
root = sqrtf(root);
|
||||||
Rmin[0] = (float)((-b - root) / divisor);
|
RMin[0] = (float)((-b - root) / divisor);
|
||||||
Rmax[0] = (float)((-b + root) / divisor);
|
RMax[0] = (float)((-b + root) / divisor);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@ float vec2_norm(vec2 v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void vec2_orthogonalize4(vec2 v) {
|
void vec2_orthogonalize4(vec2 v) {
|
||||||
if (fabs(v[0]) > fabs(v[1])) {
|
if (fabsf(v[0]) > fabsf(v[1])) {
|
||||||
if (v[0] >= 0) {
|
if (v[0] >= 0) {
|
||||||
v[0] = 1.0f;
|
v[0] = 1.0f;
|
||||||
v[1] = 0.0f;
|
v[1] = 0.0f;
|
||||||
@@ -109,9 +108,9 @@ void vec2_orthogonalize4(vec2 v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void vec2_orthogonalize8(vec2 v) {
|
void vec2_orthogonalize8(vec2 v) {
|
||||||
float diff = fabs(fabs(v[0]) - fabs(v[1]));
|
float diff = fabsf(fabsf(v[0]) - fabsf(v[1]));
|
||||||
if (diff > 0.2f) {
|
if (diff > 0.2f) {
|
||||||
if (fabs(v[0]) > fabs(v[1])) {
|
if (fabsf(v[0]) > fabsf(v[1])) {
|
||||||
if (v[0] >= 0) {
|
if (v[0] >= 0) {
|
||||||
v[0] = 1.0f;
|
v[0] = 1.0f;
|
||||||
v[1] = 0.0f;
|
v[1] = 0.0f;
|
||||||
@@ -143,10 +142,10 @@ void vec2_orthogonalize8(vec2 v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Intersec_RayUnitCircle
|
// Intersect_RayUnitCircle
|
||||||
//
|
//
|
||||||
// Intersection between a ray and a Unit Circle.
|
// Intersection between a ray and a Unit Circle.
|
||||||
int Intersec_RayUnitCircle(vec2 orig, vec2 vel, vec2 center, float *t) {
|
int Intersect_RayUnitCircle(const vec2 orig, const vec2 vel, const vec2 center, float *t) {
|
||||||
float a, b, c;
|
float a, b, c;
|
||||||
float Rmin, Rmax;
|
float Rmin, Rmax;
|
||||||
vec2 distv;
|
vec2 distv;
|
||||||
@@ -155,8 +154,9 @@ int Intersec_RayUnitCircle(vec2 orig, vec2 vel, vec2 center, float *t) {
|
|||||||
|
|
||||||
// Check if the collision is even posible
|
// Check if the collision is even posible
|
||||||
qlvel = vec2_dot(vel, vel);
|
qlvel = vec2_dot(vel, vel);
|
||||||
if (fabs(qlvel) <= 0.0f)
|
if (fabsf(qlvel) <= 0.0f) {
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
vec2_minus(distv, orig, center);
|
vec2_minus(distv, orig, center);
|
||||||
qdistv = vec2_dot(distv, distv);
|
qdistv = vec2_dot(distv, distv);
|
||||||
|
|
||||||
@@ -178,17 +178,17 @@ int Intersec_RayUnitCircle(vec2 orig, vec2 vel, vec2 center, float *t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Colision_CircleCircle
|
// Collision_CircleCircle
|
||||||
//
|
//
|
||||||
// Colision point of a circle against another circle.
|
// Collision 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 Collision_CircleCircle(const vec2 cir1, float ra, const vec2 vel, const vec2 cb, float rb, float *t, vec2 n) {
|
||||||
vec2 vel_a, orig_a, cen_a, temp;
|
vec2 vel_a, orig_a, cen_a, temp;
|
||||||
float rads, invrads;
|
float rads, invrads;
|
||||||
float maxx, minx;
|
float maxx, minx;
|
||||||
float maxy, miny;
|
float maxy, miny;
|
||||||
|
|
||||||
// Check if the collision is even posible
|
// Check if the collision is even posible
|
||||||
rads = rad1 + rad2;
|
rads = ra + rb;
|
||||||
minx = cir1[0] - rads;
|
minx = cir1[0] - rads;
|
||||||
maxx = cir1[0] + rads;
|
maxx = cir1[0] + rads;
|
||||||
if (vel[0] > 0) {
|
if (vel[0] > 0) {
|
||||||
@@ -196,7 +196,7 @@ int Colision_CircleCircle(vec2 cir1, float rad1, vec2 vel, vec2 cir2, float rad2
|
|||||||
} else {
|
} else {
|
||||||
minx += vel[0];
|
minx += vel[0];
|
||||||
}
|
}
|
||||||
if (cir2[0] < minx || cir2[0] > maxx)
|
if (cb[0] < minx || cb[0] > maxx)
|
||||||
return (0);
|
return (0);
|
||||||
miny = cir1[1] - rads;
|
miny = cir1[1] - rads;
|
||||||
maxy = cir1[1] + rads;
|
maxy = cir1[1] + rads;
|
||||||
@@ -205,18 +205,18 @@ int Colision_CircleCircle(vec2 cir1, float rad1, vec2 vel, vec2 cir2, float rad2
|
|||||||
} else {
|
} else {
|
||||||
miny += vel[1];
|
miny += vel[1];
|
||||||
}
|
}
|
||||||
if (cir2[1] < miny || cir2[1] > maxy)
|
if (cb[1] < miny || cb[1] > maxy)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
// Convert to a unit circle vs ray
|
// Convert to a unit circle vs ray
|
||||||
invrads = 1.0f / rads;
|
invrads = 1.0f / rads;
|
||||||
vec2_scale(vel_a, vel, invrads);
|
vec2_scale(vel_a, vel, invrads);
|
||||||
vec2_scale(orig_a, cir1, invrads);
|
vec2_scale(orig_a, cir1, invrads);
|
||||||
vec2_scale(cen_a, cir2, invrads);
|
vec2_scale(cen_a, cb, invrads);
|
||||||
if (Intersec_RayUnitCircle(orig_a, vel_a, cen_a, t)) {
|
if (Intersect_RayUnitCircle(orig_a, vel_a, cen_a, t)) {
|
||||||
// Calculate n
|
// Calculate n
|
||||||
vec2_scaleadd(temp, cir1, vel, *t);
|
vec2_scaleadd(temp, cir1, vel, *t);
|
||||||
vec2_minus(n, temp, cir2);
|
vec2_minus(n, temp, cb);
|
||||||
vec2_scale(n, n, invrads);
|
vec2_scale(n, n, invrads);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -226,8 +226,8 @@ int Colision_CircleCircle(vec2 cir1, float rad1, vec2 vel, vec2 cir2, float rad2
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Intersect_RayEdge
|
// Intersect_RayEdge
|
||||||
//
|
//
|
||||||
// Intersection between a ray and a edge.
|
// Intersection between a ray and an edge.
|
||||||
int Intersect_RayEdge(vec2 pos, vec2 vel, vec2 norm, vec2 edgePos, float len, float *t) {
|
int Intersect_RayEdge(const vec2 pos, const vec2 vel, const vec2 norm, const vec2 edgePos, float len, float *t) {
|
||||||
vec2 pos2, intersection, perp, edgePos2;
|
vec2 pos2, intersection, perp, edgePos2;
|
||||||
float delta, d1, d2, hLen;
|
float delta, d1, d2, hLen;
|
||||||
|
|
||||||
@@ -264,9 +264,9 @@ int Intersect_RayEdge(vec2 pos, vec2 vel, vec2 norm, vec2 edgePos, float len, fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// absmod
|
// AbsMod
|
||||||
//
|
//
|
||||||
int absmod(int v, int d) {
|
int AbsMod(int v, int d) {
|
||||||
if (v < 0) {
|
if (v < 0) {
|
||||||
v += d * (((v / d) * (-1)) + 1);
|
v += d * (((v / d) * (-1)) + 1);
|
||||||
return (v);
|
return (v);
|
||||||
@@ -274,7 +274,7 @@ int absmod(int v, int d) {
|
|||||||
return (v % d);
|
return (v % d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float fabsmod(float v, int d) {
|
float AbsModFloat(float v, int d) {
|
||||||
if (v < 0) {
|
if (v < 0) {
|
||||||
v += d * ((((int)(v / d)) * (-1)) + 1);
|
v += d * ((((int)(v / d)) * (-1)) + 1);
|
||||||
return (v);
|
return (v);
|
||||||
@@ -299,85 +299,89 @@ int IsBigEndian() {
|
|||||||
// EndsWith
|
// EndsWith
|
||||||
//
|
//
|
||||||
int EndsWith(char *str, char *suffix) {
|
int EndsWith(char *str, char *suffix) {
|
||||||
if (!str || !suffix)
|
if (!str || !suffix) {
|
||||||
return 0;
|
return 0;
|
||||||
int lenStr = strlen(str);
|
}
|
||||||
int lenSuffix = strlen(suffix);
|
size_t lenStr = strlen(str);
|
||||||
if (lenSuffix > lenStr)
|
size_t lenSuffix = strlen(suffix);
|
||||||
|
if (lenSuffix > lenStr) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return strncmp(str + lenStr - lenSuffix, suffix, lenSuffix) == 0;
|
return strncmp(str + lenStr - lenSuffix, suffix, lenSuffix) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Rand
|
// Rand
|
||||||
//
|
//
|
||||||
// (LGC++) + cambio de semilla
|
// (LGC++) + Seed change
|
||||||
|
|
||||||
#define __seed_n 30
|
#define g_LGC_Seed_N 30
|
||||||
#define __seed_a 30
|
#define g_LGC_Seed_A 30
|
||||||
#define __seed_b 5
|
#define g_LGC_Seed_B 5
|
||||||
#define __seed_c 10
|
#define g_LGC_Seed_C 10
|
||||||
#define __seed_d 15
|
#define g_LGC_Seed_D 15
|
||||||
// #define __LGC_a 1664525ul
|
#define g_LGC_A 16807ul
|
||||||
// #define __LGC_c 1013904223ul
|
#define g_LGC_C 2
|
||||||
// #define __LGC_m 4294967296ul
|
#define g_LGC_M 2147483647ul
|
||||||
#define __LGC_a 16807ul
|
unsigned g_LGC_Seeds[30];
|
||||||
#define __LGC_c 2
|
int g_LGC_Seed_I = -1;
|
||||||
#define __LGC_m 2147483647ul
|
|
||||||
unsigned __seeds[30];
|
|
||||||
int __seed_i = -1;
|
|
||||||
|
|
||||||
unsigned __rand_count;
|
unsigned g_RandCount;
|
||||||
unsigned __rand_orig_seed;
|
unsigned g_RandOrigSeed;
|
||||||
|
|
||||||
void Rand_Seed(unsigned seed) {
|
void Rand_Seed(unsigned seed) {
|
||||||
int i;
|
int i;
|
||||||
__seeds[0] = seed;
|
g_LGC_Seeds[0] = seed;
|
||||||
for (i = 1; i < 30; i++) {
|
for (i = 1; i < 30; i++) {
|
||||||
__seeds[i] = (__seeds[i - 1] * __LGC_a + __LGC_c) % __LGC_m;
|
g_LGC_Seeds[i] = (g_LGC_Seeds[i - 1] * g_LGC_A + g_LGC_C) % g_LGC_M;
|
||||||
//__seeds[i]=(__seeds[i-1]*__LGC_a+__LGC_c);
|
|
||||||
}
|
}
|
||||||
__seed_i = 29;
|
g_LGC_Seed_I = 29;
|
||||||
|
|
||||||
// Cambio de semilla
|
// Cambio de semilla
|
||||||
__rand_count = 0;
|
g_RandCount = 0;
|
||||||
__rand_orig_seed = seed;
|
g_RandOrigSeed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Rand_Get() {
|
unsigned Rand_Get() {
|
||||||
unsigned val;
|
unsigned val;
|
||||||
int a, b, c, d;
|
int a, b, c, d;
|
||||||
|
|
||||||
if (__seed_i == -1) {
|
if (g_LGC_Seed_I == -1) {
|
||||||
Rand_Seed(1);
|
Rand_Seed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
a = __seed_i - __seed_a;
|
a = g_LGC_Seed_I - g_LGC_Seed_A;
|
||||||
if (a < 0)
|
if (a < 0) {
|
||||||
a += __seed_n;
|
a += g_LGC_Seed_N;
|
||||||
b = __seed_i - __seed_b;
|
}
|
||||||
if (b < 0)
|
b = g_LGC_Seed_I - g_LGC_Seed_B;
|
||||||
b += __seed_n;
|
if (b < 0) {
|
||||||
c = __seed_i - __seed_c;
|
b += g_LGC_Seed_N;
|
||||||
if (c < 0)
|
}
|
||||||
c += __seed_n;
|
c = g_LGC_Seed_I - g_LGC_Seed_C;
|
||||||
d = __seed_i - __seed_d;
|
if (c < 0) {
|
||||||
if (d < 0)
|
c += g_LGC_Seed_N;
|
||||||
d += __seed_n;
|
}
|
||||||
val = __seeds[a] ^ __seeds[b] ^ __seeds[c] ^ __seeds[d];
|
d = g_LGC_Seed_I - g_LGC_Seed_D;
|
||||||
|
if (d < 0) {
|
||||||
|
d += g_LGC_Seed_N;
|
||||||
|
}
|
||||||
|
val = g_LGC_Seeds[a] ^ g_LGC_Seeds[b] ^ g_LGC_Seeds[c] ^ g_LGC_Seeds[d];
|
||||||
|
|
||||||
a = __seed_i - 1;
|
a = g_LGC_Seed_I - 1;
|
||||||
if (a < 0)
|
if (a < 0) {
|
||||||
a = __seed_n - 1;
|
a = g_LGC_Seed_N - 1;
|
||||||
__seeds[__seed_i] = (__seeds[a] * __LGC_a + __LGC_c) % __LGC_m;
|
}
|
||||||
//__seeds[__seed_i]=(__seeds[a]*__LGC_a+__LGC_c);
|
g_LGC_Seeds[g_LGC_Seed_I] = (g_LGC_Seeds[a] * g_LGC_A + g_LGC_C) % g_LGC_M;
|
||||||
__seed_i++;
|
g_LGC_Seed_I++;
|
||||||
if (__seed_i == __seed_n)
|
if (g_LGC_Seed_I == g_LGC_Seed_N) {
|
||||||
__seed_i = 0;
|
g_LGC_Seed_I = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Cambio de semilla
|
// Cambio de semilla
|
||||||
__rand_count++;
|
g_RandCount++;
|
||||||
if (__rand_count > (1 << 15)) {
|
if (g_RandCount > (1 << 15)) {
|
||||||
Rand_Seed(__rand_orig_seed + 1);
|
Rand_Seed(g_RandOrigSeed + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (val);
|
return (val);
|
||||||
@@ -393,7 +397,7 @@ unsigned Rand_GetBetween(int min, int max) {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Print
|
// Print
|
||||||
//
|
//
|
||||||
// Prints the formated text
|
// Prints the formatted text
|
||||||
int Print(char *fmt, ...) {
|
int Print(char *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int n;
|
int n;
|
||||||
|
|||||||
46
src/Util.h
46
src/Util.h
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2011-2021 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011-2023 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#ifndef _UTIL_H_
|
#ifndef Util_H
|
||||||
#define _UTIL_H_
|
#define Util_H
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -37,8 +37,8 @@ int Rect_PointInsideAny(TRect r[], int rCount, int x, int y);
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// SolveQuadratic
|
// SolveQuadratic
|
||||||
//
|
//
|
||||||
// Solves a Quadratic equation using a, b and c coeficients.
|
// Solves a Quadratic equation using a, b and c coefficients.
|
||||||
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 //
|
// vec2 //
|
||||||
@@ -47,57 +47,57 @@ int SolveQuadratic(float a, float b, float c, float *Rmin, float *Rmax);
|
|||||||
typedef float vec2[2];
|
typedef float vec2[2];
|
||||||
#define vec2_set(v, x, y) \
|
#define vec2_set(v, x, y) \
|
||||||
(v)[0] = (x); \
|
(v)[0] = (x); \
|
||||||
(v)[1] = (y);
|
(v)[1] = (y)
|
||||||
#define vec2_copy(v1, v2) \
|
#define vec2_copy(v1, v2) \
|
||||||
(v1)[0] = (v2)[0]; \
|
(v1)[0] = (v2)[0]; \
|
||||||
(v1)[1] = (v2)[1];
|
(v1)[1] = (v2)[1]
|
||||||
#define vec2_plus(v, v1, v2) \
|
#define vec2_plus(v, v1, v2) \
|
||||||
(v)[0] = (v1)[0] + (v2)[0]; \
|
(v)[0] = (v1)[0] + (v2)[0]; \
|
||||||
(v)[1] = (v1)[1] + (v2)[1];
|
(v)[1] = (v1)[1] + (v2)[1]
|
||||||
#define vec2_minus(v, v1, v2) \
|
#define vec2_minus(v, v1, v2) \
|
||||||
(v)[0] = (v1)[0] - (v2)[0]; \
|
(v)[0] = (v1)[0] - (v2)[0]; \
|
||||||
(v)[1] = (v1)[1] - (v2)[1];
|
(v)[1] = (v1)[1] - (v2)[1]
|
||||||
#define vec2_scale(v, v1, s) \
|
#define vec2_scale(v, v1, s) \
|
||||||
(v)[0] = (v1)[0] * (s); \
|
(v)[0] = (v1)[0] * (s); \
|
||||||
(v)[1] = (v1)[1] * (s);
|
(v)[1] = (v1)[1] * (s)
|
||||||
#define vec2_dot(v1, v2) ((v1)[0] * (v2)[0] + (v1)[1] * (v2)[1])
|
#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_len(v) sqrtf((v)[0] * (v)[0] + (v)[1] * (v)[1])
|
||||||
#define vec2_perp(v, n) \
|
#define vec2_perp(v, n) \
|
||||||
(v)[0] = -(n)[1]; \
|
(v)[0] = -(n)[1]; \
|
||||||
(v)[1] = (n)[0];
|
(v)[1] = (n)[0]
|
||||||
#define vec2_scaleadd(v, v1, v2, s) \
|
#define vec2_scaleadd(v, v1, v2, s) \
|
||||||
(v)[0] = (v2)[0] * (s) + (v1)[0]; \
|
(v)[0] = (v2)[0] * (s) + (v1)[0]; \
|
||||||
(v)[1] = (v2)[1] * (s) + (v1)[1];
|
(v)[1] = (v2)[1] * (s) + (v1)[1]
|
||||||
float vec2_norm(vec2 v);
|
float vec2_norm(vec2 v);
|
||||||
#define vec2_interpol(v, v1, v2, f) \
|
#define vec2_interpol(v, v1, v2, f) \
|
||||||
(v)[0] = (v1)[0] - f * ((v1)[0] - (v2)[0]); \
|
(v)[0] = (v1)[0] - f * ((v1)[0] - (v2)[0]); \
|
||||||
(v)[1] = (v1)[1] - f * ((v1)[1] - (v2)[1]);
|
(v)[1] = (v1)[1] - f * ((v1)[1] - (v2)[1])
|
||||||
void vec2_orthogonalize4(vec2 v);
|
void vec2_orthogonalize4(vec2 v);
|
||||||
void vec2_orthogonalize8(vec2 v);
|
void vec2_orthogonalize8(vec2 v);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Intersec_RayUnitCircle
|
// Intersect_RayUnitCircle
|
||||||
//
|
//
|
||||||
// Intersection between a ray and a Unit Circle.
|
// Intersection between a ray and a Unit Circle.
|
||||||
int Intersec_RayUnitCircle(vec2 orig, vec2 vel, vec2 center, float *t);
|
int Intersect_RayUnitCircle(const vec2 orig, const vec2 vel, const vec2 center, float *t);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Intersect_CircleCircle
|
// Collision_CircleCircle
|
||||||
//
|
//
|
||||||
// Colision point of a circle against another circle.
|
// Collision 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 Collision_CircleCircle(const vec2 cir1, float ra, const vec2 vel, const vec2 cb, float rb, float *t, vec2 n);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Intersect_RayEdge
|
// Intersect_RayEdge
|
||||||
//
|
//
|
||||||
// Intersection between a ray and a edge.
|
// Intersection between a ray and an edge.
|
||||||
int Intersect_RayEdge(vec2 pos, vec2 vel, vec2 norm, vec2 edgePos, float len, float *t);
|
int Intersect_RayEdge(const vec2 pos, const vec2 vel, const vec2 norm, const vec2 edgePos, float len, float *t);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// absmod
|
// AbsMod
|
||||||
//
|
//
|
||||||
int absmod(int v, int d);
|
int AbsMod(int v, int d);
|
||||||
float fabsmod(float v, int d);
|
float AbsModFloat(float v, int d);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// IsBigEndian
|
// IsBigEndian
|
||||||
|
|||||||
Reference in New Issue
Block a user