- [NEW] Passat a SDL3

- [NEW] Passat a de SDL_Mixer a JailAudio
- [NEW] Actualitzat a Respack2
- [NEW] Llevat el data.jrf i afegit el directori 'data' amb els arxius. Molt millor per a developar.
- [CHG] Músiques passades a OGG
- [NEW] Afegit lagueirtofile
This commit is contained in:
2025-06-29 14:18:38 +02:00
parent 7e5318c501
commit 8805799f2e
48 changed files with 6736 additions and 399 deletions

18
.gitignore vendored
View File

@@ -1,22 +1,8 @@
syntax: glob
aee
recursos/*
bin/*
obj/*
Debug/*
Release/*
data/*
*.suo
*.sdf
*.opensdf
*.user
*.dll
*.exe
.DS_Store
trick.ini
*.xcuserstate
project.xcworkspace/
xcuserdata/
*.opk
.vscode/*
data.jrf
build/*

View File

@@ -1,5 +1,6 @@
#include "bola.h"
#include "jgame.h"
#include <stdlib.h>
Bola::Bola( JD8_Surface gfx, Info* info, Prota* sam ) : Sprite( gfx ) {
this->info = info;

BIN
data.jrf

Binary file not shown.

BIN
data/00000001.ogg Normal file

Binary file not shown.

BIN
data/00000002.ogg Normal file

Binary file not shown.

BIN
data/00000003.ogg Normal file

Binary file not shown.

BIN
data/00000004.ogg Normal file

Binary file not shown.

BIN
data/00000005.ogg Normal file

Binary file not shown.

BIN
data/00000006.ogg Normal file

Binary file not shown.

BIN
data/00000007.ogg Normal file

Binary file not shown.

BIN
data/00000008.ogg Normal file

Binary file not shown.

234
data/crtpi.glsl Normal file
View File

@@ -0,0 +1,234 @@
/*
crt-pi - A Raspberry Pi friendly CRT shader.
Copyright (C) 2015-2016 davej
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
Notes:
This shader is designed to work well on Raspberry Pi GPUs (i.e. 1080P @ 60Hz on a game with a 4:3 aspect ratio). It pushes the Pi's GPU hard and enabling some features will slow it down so that it is no longer able to match 1080P @ 60Hz. You will need to overclock your Pi to the fastest setting in raspi-config to get the best results from this shader: 'Pi2' for Pi2 and 'Turbo' for original Pi and Pi Zero. Note: Pi2s are slower at running the shader than other Pis, this seems to be down to Pi2s lower maximum memory speed. Pi2s don't quite manage 1080P @ 60Hz - they drop about 1 in 1000 frames. You probably won't notice this, but if you do, try enabling FAKE_GAMMA.
SCANLINES enables scanlines. You'll almost certainly want to use it with MULTISAMPLE to reduce moire effects. SCANLINE_WEIGHT defines how wide scanlines are (it is an inverse value so a higher number = thinner lines). SCANLINE_GAP_BRIGHTNESS defines how dark the gaps between the scan lines are. Darker gaps between scan lines make moire effects more likely.
GAMMA enables gamma correction using the values in INPUT_GAMMA and OUTPUT_GAMMA. FAKE_GAMMA causes it to ignore the values in INPUT_GAMMA and OUTPUT_GAMMA and approximate gamma correction in a way which is faster than true gamma whilst still looking better than having none. You must have GAMMA defined to enable FAKE_GAMMA.
CURVATURE distorts the screen by CURVATURE_X and CURVATURE_Y. Curvature slows things down a lot.
By default the shader uses linear blending horizontally. If you find this too blury, enable SHARPER.
BLOOM_FACTOR controls the increase in width for bright scanlines.
MASK_TYPE defines what, if any, shadow mask to use. MASK_BRIGHTNESS defines how much the mask type darkens the screen.
*/
#pragma parameter CURVATURE_X "Screen curvature - horizontal" 0.10 0.0 1.0 0.01
#pragma parameter CURVATURE_Y "Screen curvature - vertical" 0.15 0.0 1.0 0.01
#pragma parameter MASK_BRIGHTNESS "Mask brightness" 0.70 0.0 1.0 0.01
#pragma parameter SCANLINE_WEIGHT "Scanline weight" 6.0 0.0 15.0 0.1
#pragma parameter SCANLINE_GAP_BRIGHTNESS "Scanline gap brightness" 0.12 0.0 1.0 0.01
#pragma parameter BLOOM_FACTOR "Bloom factor" 1.5 0.0 5.0 0.01
#pragma parameter INPUT_GAMMA "Input gamma" 2.4 0.0 5.0 0.01
#pragma parameter OUTPUT_GAMMA "Output gamma" 2.2 0.0 5.0 0.01
// Haven't put these as parameters as it would slow the code down.
#define SCANLINES
#define MULTISAMPLE
#define GAMMA
//#define FAKE_GAMMA
#define CURVATURE
//#define SHARPER
// MASK_TYPE: 0 = none, 1 = green/magenta, 2 = trinitron(ish)
#define MASK_TYPE 1
#ifdef GL_ES
#define COMPAT_PRECISION mediump
precision mediump float;
#else
#define COMPAT_PRECISION
#endif
#ifdef PARAMETER_UNIFORM
uniform COMPAT_PRECISION float CURVATURE_X;
uniform COMPAT_PRECISION float CURVATURE_Y;
uniform COMPAT_PRECISION float MASK_BRIGHTNESS;
uniform COMPAT_PRECISION float SCANLINE_WEIGHT;
uniform COMPAT_PRECISION float SCANLINE_GAP_BRIGHTNESS;
uniform COMPAT_PRECISION float BLOOM_FACTOR;
uniform COMPAT_PRECISION float INPUT_GAMMA;
uniform COMPAT_PRECISION float OUTPUT_GAMMA;
#else
#define CURVATURE_X 0.25
#define CURVATURE_Y 0.45
#define MASK_BRIGHTNESS 0.70
#define SCANLINE_WEIGHT 6.0
#define SCANLINE_GAP_BRIGHTNESS 0.12
#define BLOOM_FACTOR 1.5
#define INPUT_GAMMA 2.4
#define OUTPUT_GAMMA 2.2
#endif
/* COMPATIBILITY
- GLSL compilers
*/
//uniform vec2 TextureSize;
#if defined(CURVATURE)
varying vec2 screenScale;
#endif
varying vec2 TEX0;
varying float filterWidth;
#if defined(VERTEX)
//uniform mat4 MVPMatrix;
//attribute vec4 VertexCoord;
//attribute vec2 TexCoord;
//uniform vec2 InputSize;
//uniform vec2 OutputSize;
void main()
{
#if defined(CURVATURE)
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
#endif
filterWidth = (768.0 / 240.0) / 3.0;
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#elif defined(FRAGMENT)
uniform sampler2D Texture;
#if defined(CURVATURE)
vec2 Distort(vec2 coord)
{
vec2 CURVATURE_DISTORTION = vec2(CURVATURE_X, CURVATURE_Y);
// Barrel distortion shrinks the display area a bit, this will allow us to counteract that.
vec2 barrelScale = 1.0 - (0.23 * CURVATURE_DISTORTION);
coord *= screenScale;
coord -= vec2(0.5);
float rsq = coord.x * coord.x + coord.y * coord.y;
coord += coord * (CURVATURE_DISTORTION * rsq);
coord *= barrelScale;
if (abs(coord.x) >= 0.5 || abs(coord.y) >= 0.5)
coord = vec2(-1.0); // If out of bounds, return an invalid value.
else
{
coord += vec2(0.5);
coord /= screenScale;
}
return coord;
}
#endif
float CalcScanLineWeight(float dist)
{
return max(1.0-dist*dist*SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
}
float CalcScanLine(float dy)
{
float scanLineWeight = CalcScanLineWeight(dy);
#if defined(MULTISAMPLE)
scanLineWeight += CalcScanLineWeight(dy-filterWidth);
scanLineWeight += CalcScanLineWeight(dy+filterWidth);
scanLineWeight *= 0.3333333;
#endif
return scanLineWeight;
}
void main()
{
vec2 TextureSize = vec2(320.0, 240.0);
#if defined(CURVATURE)
vec2 texcoord = Distort(TEX0);
if (texcoord.x < 0.0)
gl_FragColor = vec4(0.0);
else
#else
vec2 texcoord = TEX0;
#endif
{
vec2 texcoordInPixels = texcoord * TextureSize;
#if defined(SHARPER)
vec2 tempCoord = floor(texcoordInPixels) + 0.5;
vec2 coord = tempCoord / TextureSize;
vec2 deltas = texcoordInPixels - tempCoord;
float scanLineWeight = CalcScanLine(deltas.y);
vec2 signs = sign(deltas);
deltas.x *= 2.0;
deltas = deltas * deltas;
deltas.y = deltas.y * deltas.y;
deltas.x *= 0.5;
deltas.y *= 8.0;
deltas /= TextureSize;
deltas *= signs;
vec2 tc = coord + deltas;
#else
float tempY = floor(texcoordInPixels.y) + 0.5;
float yCoord = tempY / TextureSize.y;
float dy = texcoordInPixels.y - tempY;
float scanLineWeight = CalcScanLine(dy);
float signY = sign(dy);
dy = dy * dy;
dy = dy * dy;
dy *= 8.0;
dy /= TextureSize.y;
dy *= signY;
vec2 tc = vec2(texcoord.x, yCoord + dy);
#endif
vec3 colour = texture2D(Texture, tc).rgb;
#if defined(SCANLINES)
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = colour * colour;
#else
colour = pow(colour, vec3(INPUT_GAMMA));
#endif
#endif
scanLineWeight *= BLOOM_FACTOR;
colour *= scanLineWeight;
#if defined(GAMMA)
#if defined(FAKE_GAMMA)
colour = sqrt(colour);
#else
colour = pow(colour, vec3(1.0/OUTPUT_GAMMA));
#endif
#endif
#endif
#if MASK_TYPE == 0
gl_FragColor = vec4(colour, 1.0);
#else
#if MASK_TYPE == 1
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.5);
vec3 mask;
if (whichMask < 0.5)
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
else
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
#elif MASK_TYPE == 2
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.3333333);
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
if (whichMask < 0.3333333)
mask.x = 1.0;
else if (whichMask < 0.6666666)
mask.y = 1.0;
else
mask.z = 1.0;
#endif
gl_FragColor = vec4(colour * mask, 1.0);
#endif
}
}
#endif

BIN
data/ffase.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
data/final.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
data/finals.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
data/frames.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
data/frames2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
data/gameover.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
data/intro.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
data/intro2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
data/intro3.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
data/logo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
data/menu.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
data/menu2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
data/tomba1.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
data/tomba2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -1,5 +1,6 @@
#include "engendro.h"
#include "jgame.h"
#include <stdlib.h>
Engendro::Engendro( JD8_Surface gfx, Uint16 x, Uint16 y ) : Sprite( gfx ) {

509
jail_audio.cpp Normal file
View File

@@ -0,0 +1,509 @@
#ifndef JA_USESDLMIXER
#include "jail_audio.h"
#include "stb_vorbis.h"
#include <SDL3/SDL.h>
#include <stdio.h>
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
struct JA_Sound_t
{
SDL_AudioSpec spec { SDL_AUDIO_S16, 2, 48000 };
Uint32 length { 0 };
Uint8 *buffer { NULL };
};
struct JA_Channel_t
{
JA_Sound_t *sound { nullptr };
int pos { 0 };
int times { 0 };
SDL_AudioStream *stream { nullptr };
JA_Channel_state state { JA_CHANNEL_FREE };
};
struct JA_Music_t
{
SDL_AudioSpec spec { SDL_AUDIO_S16, 2, 48000 };
Uint32 length { 0 };
Uint8 *buffer { nullptr };
char *filename { nullptr };
int pos { 0 };
int times { 0 };
SDL_AudioStream *stream { nullptr };
JA_Music_state state { JA_MUSIC_INVALID };
};
JA_Music_t *current_music { nullptr };
JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
SDL_AudioSpec JA_audioSpec { SDL_AUDIO_S16, 2, 48000 };
float JA_musicVolume { 1.0f };
float JA_soundVolume { 0.5f };
bool JA_musicEnabled { true };
bool JA_soundEnabled { true };
SDL_AudioDeviceID sdlAudioDevice { 0 };
SDL_TimerID JA_timerID { 0 };
bool fading = false;
int fade_start_time;
int fade_duration;
int fade_initial_volume;
/*
void audioCallback(void * userdata, uint8_t * stream, int len) {
SDL_memset(stream, 0, len);
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_musicVolume);
current_music->pos += size/2;
if (size < len) {
if (current_music->times != 0) {
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_musicVolume);
current_music->pos = (len-size)/2;
if (current_music->times > 0) current_music->times--;
} else {
current_music->pos = 0;
current_music->state = JA_MUSIC_STOPPED;
}
}
}
// Mixar els channels mi amol
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].state == JA_CHANNEL_PLAYING) {
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_soundVolume);
channels[i].pos += size;
if (size < len) {
if (channels[i].times != 0) {
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_soundVolume);
channels[i].pos = len-size;
if (channels[i].times > 0) channels[i].times--;
} else {
JA_StopChannel(i);
}
}
}
}
}
*/
Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval)
{
if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING)
{
if (fading) {
int time = SDL_GetTicks();
if (time > (fade_start_time+fade_duration)) {
fading = false;
JA_StopMusic();
return 30;
} else {
const int time_passed = time - fade_start_time;
const float percent = (float)time_passed / (float)fade_duration;
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume*(1.0 - percent));
}
}
if (current_music->times != 0)
{
if (SDL_GetAudioStreamAvailable(current_music->stream) < int(current_music->length/2)) {
SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length);
}
if (current_music->times>0) current_music->times--;
}
else
{
if (SDL_GetAudioStreamAvailable(current_music->stream) == 0) JA_StopMusic();
}
}
if (JA_soundEnabled)
{
for (int i=0; i < JA_MAX_SIMULTANEOUS_CHANNELS; ++i)
if (channels[i].state == JA_CHANNEL_PLAYING)
{
if (channels[i].times != 0)
{
if (SDL_GetAudioStreamAvailable(channels[i].stream) < int(channels[i].sound->length/2)) {
SDL_PutAudioStreamData(channels[i].stream, channels[i].sound->buffer, channels[i].sound->length);
if (channels[i].times>0) channels[i].times--;
}
}
else
{
if (SDL_GetAudioStreamAvailable(channels[i].stream) == 0) JA_StopChannel(i);
}
}
}
return 30;
}
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels)
{
#ifdef DEBUG
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
#endif
SDL_Log("Iniciant JailAudio...");
JA_audioSpec = {format, num_channels, freq };
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
SDL_Log( (sdlAudioDevice==0) ? "Failed to initialize SDL audio!\n" : "OK!\n");
for (int i=0;i<JA_MAX_SIMULTANEOUS_CHANNELS;++i) channels[i].state = JA_CHANNEL_FREE;
//SDL_PauseAudioDevice(sdlAudioDevice);
JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
}
void JA_Quit()
{
if (JA_timerID) SDL_RemoveTimer(JA_timerID);
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = 0;
}
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length, const char* filename)
{
JA_Music_t *music = new JA_Music_t();
int chan, samplerate;
short *output;
music->length = stb_vorbis_decode_memory(buffer, length, &chan, &samplerate, &output) * chan * 2;
music->spec.channels = chan;
music->spec.freq = samplerate;
music->spec.format = SDL_AUDIO_S16;
music->buffer = (Uint8*)SDL_malloc(music->length);
SDL_memcpy(music->buffer, output, music->length);
free(output);
music->pos = 0;
music->state = JA_MUSIC_STOPPED;
if (filename) {
music->filename = (char*)malloc(strlen(filename)+1);
strcpy(music->filename, filename);
}
return music;
}
JA_Music_t *JA_LoadMusic(const char* filename)
{
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
FILE *f = fopen(filename, "rb");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
Uint8 *buffer = (Uint8*)malloc(fsize + 1);
if (fread(buffer, fsize, 1, f)!=1) return NULL;
fclose(f);
JA_Music_t *music = JA_LoadMusic(buffer, fsize, filename);
free(buffer);
return music;
}
void JA_PlayMusic(JA_Music_t *music, const int loop)
{
if (!JA_musicEnabled) return;
JA_StopMusic();
current_music = music;
current_music->pos = 0;
current_music->state = JA_MUSIC_PLAYING;
current_music->times = loop;
current_music->stream = SDL_CreateAudioStream(&current_music->spec, &JA_audioSpec);
if (!SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length)) printf("[ERROR] SDL_PutAudioStreamData failed!\n");
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume);
if (!SDL_BindAudioStream(sdlAudioDevice, current_music->stream)) printf("[ERROR] SDL_BindAudioStream failed!\n");
//SDL_ResumeAudioStreamDevice(current_music->stream);
}
char *JA_GetMusicFilename(JA_Music_t *music)
{
if (!music) music = current_music;
return music->filename;
}
void JA_PauseMusic()
{
if (!JA_musicEnabled) return;
if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
current_music->state = JA_MUSIC_PAUSED;
//SDL_PauseAudioStreamDevice(current_music->stream);
SDL_UnbindAudioStream(current_music->stream);
}
void JA_ResumeMusic()
{
if (!JA_musicEnabled) return;
if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
current_music->state = JA_MUSIC_PLAYING;
//SDL_ResumeAudioStreamDevice(current_music->stream);
SDL_BindAudioStream(sdlAudioDevice, current_music->stream);
}
void JA_StopMusic()
{
if (!JA_musicEnabled) return;
if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
current_music->pos = 0;
current_music->state = JA_MUSIC_STOPPED;
//SDL_PauseAudioStreamDevice(current_music->stream);
SDL_DestroyAudioStream(current_music->stream);
current_music->stream = nullptr;
free(current_music->filename);
current_music->filename = nullptr;
}
void JA_FadeOutMusic(const int milliseconds)
{
if (!JA_musicEnabled) return;
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
fading = true;
fade_start_time = SDL_GetTicks();
fade_duration = milliseconds;
fade_initial_volume = JA_musicVolume;
}
JA_Music_state JA_GetMusicState()
{
if (!JA_musicEnabled) return JA_MUSIC_DISABLED;
if (!current_music) return JA_MUSIC_INVALID;
return current_music->state;
}
void JA_DeleteMusic(JA_Music_t *music)
{
if (current_music == music) current_music = nullptr;
SDL_free(music->buffer);
if (music->stream) SDL_DestroyAudioStream(music->stream);
delete music;
}
float JA_SetMusicVolume(float volume)
{
JA_musicVolume = SDL_clamp( volume, 0.0f, 1.0f );
if (current_music) SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume);
return JA_musicVolume;
}
void JA_SetMusicPosition(float value)
{
if (!current_music) return;
current_music->pos = value * current_music->spec.freq;
}
float JA_GetMusicPosition()
{
if (!current_music) return 0;
return float(current_music->pos)/float(current_music->spec.freq);
}
void JA_EnableMusic(const bool value)
{
if ( !value && current_music && (current_music->state==JA_MUSIC_PLAYING) ) JA_StopMusic();
JA_musicEnabled = value;
}
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length)
{
JA_Sound_t *sound = new JA_Sound_t();
sound->buffer = buffer;
sound->length = length;
return sound;
}
JA_Sound_t *JA_LoadSound(uint8_t* buffer, uint32_t size)
{
JA_Sound_t *sound = new JA_Sound_t();
SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size),1, &sound->spec, &sound->buffer, &sound->length);
return sound;
}
JA_Sound_t *JA_LoadSound(const char* filename)
{
JA_Sound_t *sound = new JA_Sound_t();
SDL_LoadWAV(filename, &sound->spec, &sound->buffer, &sound->length);
return sound;
}
int JA_PlaySound(JA_Sound_t *sound, const int loop)
{
if (!JA_soundEnabled) return -1;
int channel = 0;
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0;
JA_StopChannel(channel);
channels[channel].sound = sound;
channels[channel].times = loop;
channels[channel].pos = 0;
channels[channel].state = JA_CHANNEL_PLAYING;
channels[channel].stream = SDL_CreateAudioStream(&channels[channel].sound->spec, &JA_audioSpec);
SDL_PutAudioStreamData(channels[channel].stream, channels[channel].sound->buffer, channels[channel].sound->length);
SDL_SetAudioStreamGain(channels[channel].stream, JA_soundVolume);
SDL_BindAudioStream(sdlAudioDevice, channels[channel].stream);
return channel;
}
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop)
{
if (!JA_soundEnabled) return -1;
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return -1;
JA_StopChannel(channel);
channels[channel].sound = sound;
channels[channel].times = loop;
channels[channel].pos = 0;
channels[channel].state = JA_CHANNEL_PLAYING;
channels[channel].stream = SDL_CreateAudioStream(&channels[channel].sound->spec, &JA_audioSpec);
SDL_PutAudioStreamData(channels[channel].stream, channels[channel].sound->buffer, channels[channel].sound->length);
SDL_SetAudioStreamGain(channels[channel].stream, JA_soundVolume);
SDL_BindAudioStream(sdlAudioDevice, channels[channel].stream);
return channel;
}
void JA_DeleteSound(JA_Sound_t *sound)
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].sound == sound) JA_StopChannel(i);
}
SDL_free(sound->buffer);
delete sound;
}
void JA_PauseChannel(const int channel)
{
if (!JA_soundEnabled) return;
if (channel == -1)
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
if (channels[i].state == JA_CHANNEL_PLAYING)
{
channels[i].state = JA_CHANNEL_PAUSED;
//SDL_PauseAudioStreamDevice(channels[i].stream);
SDL_UnbindAudioStream(channels[i].stream);
}
}
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
{
if (channels[channel].state == JA_CHANNEL_PLAYING)
{
channels[channel].state = JA_CHANNEL_PAUSED;
//SDL_PauseAudioStreamDevice(channels[channel].stream);
SDL_UnbindAudioStream(channels[channel].stream);
}
}
}
void JA_ResumeChannel(const int channel)
{
if (!JA_soundEnabled) return;
if (channel == -1)
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
if (channels[i].state == JA_CHANNEL_PAUSED)
{
channels[i].state = JA_CHANNEL_PLAYING;
//SDL_ResumeAudioStreamDevice(channels[i].stream);
SDL_BindAudioStream(sdlAudioDevice, channels[i].stream);
}
}
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
{
if (channels[channel].state == JA_CHANNEL_PAUSED)
{
channels[channel].state = JA_CHANNEL_PLAYING;
//SDL_ResumeAudioStreamDevice(channels[channel].stream);
SDL_BindAudioStream(sdlAudioDevice, channels[channel].stream);
}
}
}
void JA_StopChannel(const int channel)
{
if (!JA_soundEnabled) return;
if (channel == -1)
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
if (channels[i].state != JA_CHANNEL_FREE) SDL_DestroyAudioStream(channels[i].stream);
channels[i].stream = nullptr;
channels[i].state = JA_CHANNEL_FREE;
channels[i].pos = 0;
channels[i].sound = NULL;
}
}
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
{
if (channels[channel].state != JA_CHANNEL_FREE) SDL_DestroyAudioStream(channels[channel].stream);
channels[channel].stream = nullptr;
channels[channel].state = JA_CHANNEL_FREE;
channels[channel].pos = 0;
channels[channel].sound = NULL;
}
}
JA_Channel_state JA_GetChannelState(const int channel)
{
if (!JA_soundEnabled) return JA_SOUND_DISABLED;
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
return channels[channel].state;
}
float JA_SetSoundVolume(float volume)
{
JA_soundVolume = SDL_clamp( volume, 0.0f, 1.0f );
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
if ( (channels[i].state == JA_CHANNEL_PLAYING) || (channels[i].state == JA_CHANNEL_PAUSED) )
SDL_SetAudioStreamGain(channels[i].stream, JA_soundVolume);
return JA_soundVolume;
}
void JA_EnableSound(const bool value)
{
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
{
if (channels[i].state == JA_CHANNEL_PLAYING) JA_StopChannel(i);
}
JA_soundEnabled = value;
}
float JA_SetVolume(float volume)
{
JA_SetSoundVolume(JA_SetMusicVolume(volume) / 2.0f);
return JA_musicVolume;
}
#endif

41
jail_audio.h Normal file
View File

@@ -0,0 +1,41 @@
#pragma once
#include <SDL3/SDL.h>
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED, JA_SOUND_DISABLED };
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED, JA_MUSIC_DISABLED };
struct JA_Sound_t;
struct JA_Music_t;
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels);
void JA_Quit();
JA_Music_t *JA_LoadMusic(const char* filename);
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length, const char* filename=nullptr);
void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
char *JA_GetMusicFilename(JA_Music_t *music = nullptr);
void JA_PauseMusic();
void JA_ResumeMusic();
void JA_StopMusic();
void JA_FadeOutMusic(const int milliseconds);
JA_Music_state JA_GetMusicState();
void JA_DeleteMusic(JA_Music_t *music);
float JA_SetMusicVolume(float volume);
void JA_SetMusicPosition(float value);
float JA_GetMusicPosition();
void JA_EnableMusic(const bool value);
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length);
JA_Sound_t *JA_LoadSound(Uint8* buffer, Uint32 length);
JA_Sound_t *JA_LoadSound(const char* filename);
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop = 0);
void JA_PauseChannel(const int channel);
void JA_ResumeChannel(const int channel);
void JA_StopChannel(const int channel);
JA_Channel_state JA_GetChannelState(const int channel);
void JA_DeleteSound(JA_Sound_t *sound);
float JA_SetSoundVolume(float volume);
void JA_EnableSound(const bool value);
float JA_SetVolume(float volume);

View File

@@ -33,16 +33,16 @@ void JD8_Init(const char *title) {
main_palette = (JD8_Palette)calloc( 1, 768 );
pixel_data = (Uint32*)calloc(1, 320 * 200 * 4); // 1048576 );
sdlWindow = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
sdlWindow = SDL_CreateWindow( title, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL );
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
sdlRenderer = SDL_CreateRenderer(sdlWindow, NULL);
sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, 320, 200);
backBuffer = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, 320, 200);
int filesize = 0;
char *buffer = JF_GetBufferFromResource("crtpi.glsl", filesize, true);
char *buffer = file_getfilebuffer("crtpi.glsl", filesize, true);
shader::init(sdlWindow, backBuffer, buffer);
free(buffer);
@@ -68,7 +68,7 @@ JD8_Surface JD8_NewSurface() {
JD8_Surface JD8_LoadSurface(const char *file) {
int filesize = 0;
char *buffer = JF_GetBufferFromResource(file, filesize);
char *buffer = file_getfilebuffer(file, filesize);
unsigned short w, h;
Uint8* pixels = LoadGif((unsigned char*)buffer, &w, &h);
@@ -90,7 +90,7 @@ JD8_Surface JD8_LoadSurface(const char *file) {
JD8_Palette JD8_LoadPalette(const char *file) {
int filesize = 0;
char *buffer = NULL;
buffer = JF_GetBufferFromResource(file, filesize);
buffer = file_getfilebuffer(file, filesize);
JD8_Palette palette = (JD8_Palette)LoadPalette((unsigned char*)buffer);
@@ -191,7 +191,7 @@ void JD8_Flip() {
}
SDL_UpdateTexture(sdlTexture, NULL, pixel_data, 320 * sizeof(Uint32));
SDL_SetRenderTarget(sdlRenderer, backBuffer);
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
SDL_RenderTexture(sdlRenderer, sdlTexture, NULL, NULL);
shader::render();
//SDL_RenderPresent(sdlRenderer);
}

View File

@@ -1,5 +1,5 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL3/SDL.h>
struct Color {
Uint8 r;

321
jfile.cpp
View File

@@ -1,71 +1,109 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include "jfile.h"
#include <SDL2/SDL.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>
#include <fstream>
#include <filesystem>
#include <string>
#include <vector>
#pragma pack(push,1)
#ifndef _WIN32
#include <pwd.h>
#endif
struct DATA_Header {
char magic[4];
Uint32 num_files;
Uint32 index_offset;
#define DEFAULT_FILENAME "data.jf2"
#define DEFAULT_FOLDER "data/"
#define CONFIG_FILENAME "config.txt"
struct file_t
{
std::string path;
uint32_t size;
uint32_t offset;
};
struct DATA_Info {
Uint32 offset;
Uint32 length;
char name[13];
std::vector<file_t> toc;
/* El std::map me fa coses rares, vaig a usar un good old std::vector amb una estructura key,value propia i au, que sempre funciona */
struct keyvalue_t {
std::string key, value;
};
struct DATA_Index {
DATA_Info* file_info;
};
char *resource_filename = NULL;
char *resource_folder = NULL;
int file_source = SOURCE_FILE;
char scratch[255];
static std::string config_folder;
std::vector<keyvalue_t> config;
struct DATA_File {
DATA_Header header;
DATA_Index index;
};
#pragma pack(pop)
const char *resourceFileName = "data.jrf";
DATA_File *data_file = NULL;
void JF_SetResourceFile(const char *p_resourceFileName) {
resourceFileName = p_resourceFileName;
void file_setresourcefilename(const char *str) {
if (resource_filename != NULL) free(resource_filename);
resource_filename = (char*)malloc(strlen(str)+1);
strcpy(resource_filename, str);
}
void JF_GetDataFile() {
std::ifstream fd( resourceFileName, std::ios::in | std::ios::binary );
if( fd.fail() ) {
perror("No s'ha pogut obrir l'arxiu de recursos");
exit(1);
}
data_file = (DATA_File*)malloc( sizeof( DATA_File ) );
fd.read( (char*)&data_file->header, sizeof( DATA_Header ) );
fd.seekg( data_file->header.index_offset );
data_file->index.file_info = (DATA_Info*)malloc( data_file->header.num_files * sizeof( DATA_Info ) );
fd.read( (char*)data_file->index.file_info, data_file->header.num_files * sizeof( DATA_Info ) );
fd.close();
void file_setresourcefolder(const char *str) {
if (resource_folder != NULL) free(resource_folder);
resource_folder = (char*)malloc(strlen(str)+1);
strcpy(resource_folder, str);
}
char *JF_GetBufferFromResource(const char *resourcename, int& filesize, const bool addZero) {
void file_setsource(const int src) {
file_source = src%2; // mod 2 so it always is a valid value, 0 (file) or 1 (folder)
if (src==SOURCE_FOLDER && resource_folder==NULL) file_setresourcefolder(DEFAULT_FOLDER);
}
if( data_file == NULL ) {
JF_GetDataFile();
bool file_getdictionary() {
if (resource_filename == NULL) file_setresourcefilename(DEFAULT_FILENAME);
std::ifstream fi (resource_filename, std::ios::binary);
if (!fi.is_open()) return false;
char header[4];
fi.read(header, 4);
uint32_t num_files, toc_offset;
fi.read((char*)&num_files, 4);
fi.read((char*)&toc_offset, 4);
fi.seekg(toc_offset);
for (int i=0; i<num_files; ++i)
{
uint32_t file_offset, file_size;
fi.read( (char*)&file_offset, 4 );
fi.read( (char*)&file_size, 4 );
uint8_t path_size;
fi.read( (char*)&path_size, 1 );
char file_name[path_size+1];
fi.read( file_name, path_size );
file_name[path_size] = 0;
std::string filename = file_name;
toc.push_back({filename, file_size, file_offset});
}
fi.close();
}
char *file_getfilenamewithfolder(const char* filename) {
strcpy(scratch, resource_folder);
strcat(scratch, filename);
return scratch;
}
FILE *file_getfilepointer(const char *resourcename, int& filesize, const bool binary) {
if (file_source==SOURCE_FILE and toc.size()==0) {
if (not file_getdictionary()) file_setsource(SOURCE_FOLDER);
}
FILE *f;
if (file_source==SOURCE_FILE) {
bool found = false;
int count = 0;
while( !found && count < data_file->header.num_files ) {
found = ( strcmp( resourcename, data_file->index.file_info[count].name ) == 0 );
uint32_t count = 0;
while( !found && count < toc.size() ) {
found = ( std::string(resourcename) == toc[count].path );
if( !found ) count++;
}
@@ -74,90 +112,119 @@ char *JF_GetBufferFromResource(const char *resourcename, int& filesize, const bo
exit(1);
}
filesize = data_file->index.file_info[count].length;
filesize = toc[count].size;
std::ifstream fd( resourceFileName, std::ios::in | std::ios::binary );
if( fd.fail() ) {
f = fopen(resource_filename, binary?"rb":"r");
if (not f) {
perror("No s'ha pogut obrir l'arxiu de recursos");
exit(1);
}
fseek(f, toc[count].offset, SEEK_SET);
} else {
f = fopen(file_getfilenamewithfolder(resourcename), binary?"rb":"r");
fseek(f, 0, SEEK_END);
filesize = ftell(f);
fseek(f, 0, SEEK_SET);
}
return f;
}
fd.seekg( data_file->index.file_info[count].offset );
char* buffer = (char*)malloc( filesize + (addZero ? 1 : 0) );
fd.read( buffer, filesize );
fd.close();
if (addZero) buffer[filesize] = 0;
char *file_getfilebuffer(const char *resourcename, int& filesize, const bool zero_terminate) {
FILE *f = file_getfilepointer(resourcename, filesize, true);
char* buffer = (char*)malloc(zero_terminate?filesize:filesize+1);
fread(buffer, filesize, 1, f);
if (zero_terminate) buffer[filesize]=0;
fclose(f);
return buffer;
}
// //Read the first INT, which will tell us how many files are in this resource
// int numfiles;
// int resultat = read(fd, &numfiles, sizeof(int));
//
//#ifdef _WIN32
// int final = eof(fd);
//#endif
//
// //Get the pointers to the stored files
// int *filestart = (int *) malloc(sizeof(int) * numfiles);
// resultat = read(fd, filestart, sizeof(int) * numfiles);
//
// //Loop through the files, looking for the file in question
// int filenamesize;
// char *buffer;
// int i;
// for(i=0;i<numfiles;i++)
// {
// int result = 129;
// char *filename;
// //Seek to the location
// lseek(fd, filestart[i], SEEK_SET);
// //Get the filesize value
// read(fd, filesize, sizeof(int));
// //Get the size of the filename string
// read(fd, &filenamesize, sizeof(int));
// //Size the buffer and read the filename
// filename = (char *) malloc(filenamesize + 1);
// result = read(fd, filename, filenamesize);
// //Remember to terminate the string properly!
// filename[filenamesize] = '\0';
// //Compare to the string we're looking for
// if (strcmp(filename, resourcename) == 0)
// {
// //Get the contents of the file
// buffer = (char *) malloc(*filesize);
// read(fd, buffer, *filesize);
// free(filename);
// break;
// }
// //Free the filename buffer
// free(filename);
// }
//
// //Release memory
// free(filestart);
//
// //Close the resource file!
// close(fd);
//
// //Did we find the file within the resource that we were looking for?
// if (buffer == NULL)
// {
// printf("Unable to find '%s' in the resource file!\n", resourcename);
// exit(1);
// }
//
// //Return the buffer
// return buffer;
//}
// Crea la carpeta del sistema donde guardar datos
void file_setconfigfolder(const char *foldername)
{
#ifdef _WIN32
config_folder = std::string(getenv("APPDATA")) + "/" + foldername;
#elif __APPLE__
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
config_folder = std::string(homedir) + "/Library/Application Support/" + foldername;
#elif __linux__
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
config_folder = std::string(homedir) + "/." + foldername;
#endif
void JF_Quit() {
if( data_file != NULL ) {
free( data_file->index.file_info );
free( data_file );
struct stat st = {0};
if (stat(config_folder.c_str(), &st) == -1)
{
#ifdef _WIN32
int ret = mkdir(config_folder.c_str());
#else
int ret = mkdir(config_folder.c_str(), S_IRWXU);
#endif
if (ret == -1)
{
printf("ERROR CREATING CONFIG FOLDER.");
exit(EXIT_FAILURE);
}
}
}
const char *file_getconfigfolder() {
std::string folder = config_folder + "/";
return folder.c_str();
}
void file_loadconfigvalues() {
config.clear();
std::string config_file = config_folder + "/config.txt";
FILE *f = fopen(config_file.c_str(), "r");
if (!f) return;
char line[1024];
while (fgets(line, sizeof(line), f)) {
char *value = strchr(line, '=');
if (value) {
*value='\0'; value++;
value[strlen(value)-1] = '\0';
config.push_back({line, value});
}
}
fclose(f);
}
void file_saveconfigvalues() {
std::string config_file = config_folder + "/config.txt";
FILE *f = fopen(config_file.c_str(), "w");
if (f) {
for (auto pair : config) {
fprintf(f, "%s=%s\n", pair.key.c_str(), pair.value.c_str());
}
fclose(f);
}
}
const char* file_getconfigvalue(const char *key) {
if (config.empty()) file_loadconfigvalues();
for (auto pair : config) {
if (pair.key == std::string(key)) {
strcpy(scratch, pair.value.c_str());
return scratch;
}
}
return NULL;
}
void file_setconfigvalue(const char* key, const char* value) {
if (config.empty()) file_loadconfigvalues();
for (auto &pair : config) {
if (pair.key == std::string(key)) {
pair.value = value;
file_saveconfigvalues();
return;
}
}
config.push_back({key, value});
file_saveconfigvalues();
return;
}

17
jfile.h
View File

@@ -1,7 +1,18 @@
#pragma once
#include <stdio.h>
void JF_SetResourceFile(const char *p_resourceFileName);
#define SOURCE_FILE 0
#define SOURCE_FOLDER 1
char *JF_GetBufferFromResource(const char *resourcename, int& filesize, const bool addZero=false);
void file_setconfigfolder(const char *foldername);
const char *file_getconfigfolder();
void JF_Quit();
void file_setresourcefilename(const char *str);
void file_setresourcefolder(const char *str);
void file_setsource(const int src);
FILE *file_getfilepointer(const char *resourcename, int& filesize, const bool binary=false);
char *file_getfilebuffer(const char *resourcename, int& filesize, const bool zero_terminate=false);
const char* file_getconfigvalue(const char *key);
void file_setconfigvalue(const char* key, const char* value);

View File

@@ -7,7 +7,7 @@ Uint32 cycle_counter = 0;
void JG_Init() {
SDL_Init( SDL_INIT_EVERYTHING );
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO );
//SDL_WM_SetCaption( title, NULL );
updateTime = SDL_GetTicks();
}

View File

@@ -1,5 +1,5 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL3/SDL.h>
void JG_Init();

View File

@@ -2,7 +2,7 @@
#include "jgame.h"
#include <string>
const Uint8 *keystates;// = SDL_GetKeyboardState( NULL );
const bool *keystates;// = SDL_GetKeyboardState( NULL );
SDL_Event event;
Uint8 cheat[5];
bool key_pressed = false;
@@ -27,10 +27,10 @@ void JI_Update() {
if (waitTime > 0) waitTime--;
while ( SDL_PollEvent( &event ) ) {
if ( event.type == SDL_QUIT ) JG_QuitSignal();
if( event.type == SDL_KEYUP ) {
if ( event.type == SDL_EVENT_QUIT ) JG_QuitSignal();
if( event.type == SDL_EVENT_KEY_UP ) {
key_pressed = true;
JI_moveCheats( event.key.keysym.sym );
JI_moveCheats( event.key.scancode );
}
}
}

View File

@@ -1,5 +1,5 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL3/SDL.h>
void JI_DisableKeyboard(Uint32 time);

View File

@@ -12,8 +12,8 @@
#include <OpenGL/gl.h>
#endif //!ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
#else
#include <SDL2/SDL_opengl.h>
#include <SDL2/SDL_opengl_glext.h>
#include <SDL3/SDL_opengl.h>
#include <SDL3/SDL_opengl_glext.h>
#endif
namespace shader
@@ -23,8 +23,10 @@ namespace shader
GLuint programId = 0;
SDL_Texture* backBuffer = nullptr;
SDL_Point win_size = {640, 480};
SDL_Point tex_size = {320, 240};
SDL_FPoint tex_size = {320, 240};
bool usingOpenGL;
GLuint texture_number;
GLuint nose;
#ifndef __APPLE__
@@ -80,7 +82,8 @@ namespace shader
//Check vertex shader for errors
GLint shaderCompiled = GL_FALSE;
glGetShaderiv( result, GL_COMPILE_STATUS, &shaderCompiled );
if( shaderCompiled != GL_TRUE ) {
if (shaderCompiled != GL_TRUE)
{
std::cout << "Error en la compilación: " << result << "!" << std::endl;
GLint logLength;
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength);
@@ -93,13 +96,12 @@ namespace shader
}
glDeleteShader(result);
result = 0;
// } else {
// std::cout << "Shader compilado correctamente. Id = " << result << std::endl;
}
return result;
}
GLuint compileProgram(const char* vertexShaderSource, const char* fragmentShaderSource) {
GLuint compileProgram(const char* vertexShaderSource, const char* fragmentShaderSource)
{
GLuint programId = 0;
GLuint vtxShaderId, fragShaderId;
@@ -108,7 +110,8 @@ namespace shader
vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
fragShaderId = compileShader(fragmentShaderSource?fragmentShaderSource:vertexShaderSource, GL_FRAGMENT_SHADER);
if(vtxShaderId && fragShaderId) {
if(vtxShaderId && fragShaderId)
{
// Associate shader with program
glAttachShader(programId, vtxShaderId);
glAttachShader(programId, fragShaderId);
@@ -118,7 +121,8 @@ namespace shader
// Check the status of the compile/link
GLint logLen;
glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen);
if(logLen > 0) {
if (logLen > 0)
{
char* log = (char*) malloc(logLen * sizeof(char));
// Show any errors as appropriate
glGetProgramInfoLog(programId, logLen, &logLen, log);
@@ -126,12 +130,8 @@ namespace shader
free(log);
}
}
if(vtxShaderId) {
glDeleteShader(vtxShaderId);
}
if(fragShaderId) {
glDeleteShader(fragShaderId);
}
if (vtxShaderId) glDeleteShader(vtxShaderId);
if (fragShaderId) glDeleteShader(fragShaderId);
return programId;
}
@@ -141,29 +141,34 @@ namespace shader
shader::renderer = SDL_GetRenderer(win);
shader::backBuffer = backBuffer;
SDL_GetWindowSize(win, &win_size.x, &win_size.y);
int access;
SDL_QueryTexture(backBuffer, NULL, &access, &tex_size.x, &tex_size.y);
SDL_GetTextureSize(backBuffer, &tex_size.x, &tex_size.y);
printf("tex size: %fx%f\n", tex_size.x, tex_size.y);
SDL_PropertiesID props = SDL_GetTextureProperties(backBuffer);
texture_number = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER, -1);
printf("texture number: %i\n", texture_number);
int access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, -1);
nose = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER, -1);
printf("texture target number: %i\n", nose);
if (access != SDL_TEXTUREACCESS_TARGET)
{
std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl;
exit(1);
}
SDL_RendererInfo rendererInfo;
SDL_GetRendererInfo(renderer, &rendererInfo);
const char * renderer_name = SDL_GetRendererName(renderer);
printf("rendererInfo.name: %s\n", renderer_name);
if(!strncmp(rendererInfo.name, "opengl", 6)) {
//std::cout << "Es OpenGL!" << std::endl;
#ifndef __APPLE__
if(!strncmp(renderer_name, "opengl", 6)) {
#ifndef __APPLE__
if (!initGLExtensions()) {
std::cout << "WARNING: No s'han pogut inicialitzar les extensions d'OpenGL!" << std::endl;
usingOpenGL = false;
return false;
}
#endif
#endif
// Compilar el shader y dejarlo listo para usar.
programId = compileProgram(vertexShader, fragmentShader);
//std::cout << "programId = " << programId << std::endl;
} else {
std::cout << "WARNING: El driver del renderer no es OpenGL." << std::endl;
usingOpenGL = false;
@@ -173,57 +178,54 @@ namespace shader
return true;
}
unsigned char pixels[512*240*4];
void render()
{
GLint oldProgramId;
// Guarrada para obtener el textureid (en driverdata->texture)
//Detach the texture
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_FlushRenderer(renderer);
SDL_SetRenderTarget(renderer, NULL);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_FlushRenderer(renderer);
if (usingOpenGL) {
SDL_GL_BindTexture(backBuffer, NULL, NULL);
if(programId != 0) {
glGetIntegerv(GL_CURRENT_PROGRAM,&oldProgramId);
if (usingOpenGL)
{
GLint oldProgramId;
if (programId != 0)
{
glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId);
glUseProgram(programId);
}
GLfloat minx, miny, maxx, maxy;
GLfloat minu, maxu, minv, maxv;
// Coordenadas de la ventana donde pintar.
minx = 0.0f;
miny = 0.0f;
maxx = tex_size.x;
maxy = tex_size.y;
minu = 0.0f;
maxu = 1.0f;
minv = 0.0f;
maxv = 1.0f;
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 1);
//glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels);
//if (glGetError()) { printf("GLGETERROR!\n"); exit(1);}
//GLint param;
//glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &param);
//printf("tex width: %i\n", param);
glViewport(0, 0, win_size.x, win_size.y);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(minu, minv);
glVertex2f(minx, miny);
glTexCoord2f(maxu, minv);
glVertex2f(maxx, miny);
glTexCoord2f(minu, maxv);
glVertex2f(minx, maxy);
glTexCoord2f(maxu, maxv);
glVertex2f(maxx, maxy);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(tex_size.x, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(0.0f, tex_size.y);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(tex_size.x, tex_size.y);
glEnd();
SDL_GL_SwapWindow(win);
if(programId != 0) {
glUseProgram(oldProgramId);
}
if (programId != 0) glUseProgram(oldProgramId);
} else {
SDL_RenderCopy(renderer, backBuffer, NULL, NULL);
SDL_RenderTexture(renderer, backBuffer, NULL, NULL);
SDL_RenderPresent(renderer);
}
if (glGetError()) { printf("GLERROR!\n"); exit(1); }
}
}

View File

@@ -1,6 +1,6 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL3/SDL.h>
// TIPS:
// =======================================================================

View File

@@ -1,79 +0,0 @@
#include "jsound.h"
#include "jfile.h"
#include <string>
Mix_Music *music = NULL;
char currentMusic[12];
bool JS_Init() {
Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
Mix_AllocateChannels(8);
currentMusic[0] = 0;
return true;
}
void JS_LoadMusic(const char *musicFilename)
{
if (music != NULL) {
Mix_HaltMusic();
Mix_FreeMusic(music);
}
Mix_VolumeMusic(MIX_MAX_VOLUME);
int filesize = 0;
char *buffer = JF_GetBufferFromResource(musicFilename, filesize);
SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
music = Mix_LoadMUS_RW(rw, 1);
strcpy(currentMusic, musicFilename);
}
void JS_SetMusicVolume(int volume) {
Mix_VolumeMusic(volume);
}
void JS_PlayMusic(int loops) {
Mix_PlayMusic(music, loops);
}
void JS_PauseMusic() {
Mix_PauseMusic();
}
void JS_FadeOutMusic() {
Mix_FadeOutMusic(500);
}
bool JS_MusicPlaying() {
return (Mix_PlayingMusic() == 1);// && (Mix_FadingMusic() != MIX_FADING_OUT);
}
const char* JS_GetMusicName() {
return currentMusic;
}
JS_Sound *JS_LoadSound(char *soundFilename) {
int filesize = 0;
char *buffer = JF_GetBufferFromResource(soundFilename, filesize);
SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
return Mix_LoadWAV_RW(rw, false);
}
void JS_SetSoundVolume(JS_Sound *sound, int volume) {
Mix_VolumeChunk(sound, volume);
}
void JS_PlaySound(JS_Sound *sound) {
Mix_PlayChannel(-1, sound, 0);
}
void JS_FreeSound(JS_Sound *sound) {
Mix_FreeChunk(sound);
}
void JS_Finalize() {
Mix_FreeMusic(music);
Mix_CloseAudio();
}

View File

@@ -1,30 +0,0 @@
#pragma once
#include <SDL2/SDL_mixer.h>
typedef Mix_Chunk JS_Sound;
bool JS_Init();
void JS_LoadMusic(const char *musicFilename);
void JS_SetMusicVolume(int volume);
void JS_PlayMusic(int loops);
void JS_PauseMusic();
void JS_FadeOutMusic();
bool JS_MusicPlaying();
const char* JS_GetMusicName();
JS_Sound *JS_LoadSound(char *soundFilename);
void JS_SetSoundVolume(JS_Sound *sound, int volume);
void JS_PlaySound(JS_Sound *sound);
void JS_FreeSound(JS_Sound *sound);
void JS_Finalize();

5
lagueirtofile Normal file
View File

@@ -0,0 +1,5 @@
libs = -lSDL3 -lGL
cppflags = -D DEBUG -D VERBOSE -g -Wall
executable = aee
sourcepath = .
buildpath = build

View File

@@ -1,6 +1,6 @@
#include "jgame.h"
#include "jdraw8.h"
#include "jsound.h"
#include "jail_audio.h"
#include "jfile.h"
#include "info.h"
#include "modulegame.h"
@@ -16,7 +16,7 @@
int main( int argc, char* args[] ) {
JF_SetResourceFile("data.jrf");
file_setresourcefilename("data.jrf");
/*#ifdef WIN32
JF_SetResourceFile("data.jrf");
#else
@@ -35,7 +35,7 @@ int main( int argc, char* args[] ) {
JG_Init();
JD8_Init("Aventures En Egipte");
JS_Init();
JA_Init(48000, SDL_AUDIO_S16, 2);
Info info;
info.num_habitacio = 1;
@@ -72,8 +72,7 @@ int main( int argc, char* args[] ) {
}
}
JF_Quit();
JS_Finalize();
JA_Quit();
JD8_Quit();
JG_Finalize();

View File

@@ -2,7 +2,7 @@
#include "jgame.h"
#include "jdraw8.h"
#include "jsound.h"
#include "jail_audio.h"
#include "jinput.h"
#include "jfile.h"
@@ -49,10 +49,12 @@ int ModuleGame::Go() {
this->Draw();
const char* music = this->info->num_piramide == 3 ? "00000008.xm" : (this->info->num_piramide == 2 ? "00000007.xm" : (this->info->num_piramide == 6 ? "00000002.xm" : "00000006.xm"));
if (!JS_MusicPlaying() || !(SDL_strcmp(music, JS_GetMusicName()) == 0)) {
JS_LoadMusic(music);
JS_PlayMusic(-1);
const char* music = this->info->num_piramide == 3 ? "00000008.ogg" : (this->info->num_piramide == 2 ? "00000007.ogg" : (this->info->num_piramide == 6 ? "00000002.ogg" : "00000006.ogg"));
const char *current_music = JA_GetMusicFilename();
if ( (JA_GetMusicState()!=JA_MUSIC_PLAYING) || !(strcmp(music, current_music) == 0)) {
int size;
char *buffer = file_getfilebuffer(music, size);
JA_PlayMusic(JA_LoadMusic((Uint8*)buffer, size, music));
}
JD8_FadeToPal( JD8_LoadPalette(this->info->pepe_activat ? "frames2.gif" : "frames.gif") );

View File

@@ -3,7 +3,8 @@
#include "jgame.h"
#include "jdraw8.h"
#include "jinput.h"
#include "jsound.h"
#include "jfile.h"
#include "jail_audio.h"
#include <stdlib.h>
#include <string>
@@ -22,14 +23,14 @@ int ModuleSequence::Go() {
case 255: // Intro
doIntro();
break;
case 0: // Men<65>
case 0: // Men<65>
doMenu();
break;
case 1: // Slides
case 7:
doSlides();
break;
case 2: // Pre-pir<69>mide
case 2: // Pre-pir<69>mide
case 3:
case 4:
case 5:
@@ -80,11 +81,17 @@ const int minim( const int a, const int b ) {
if( b < a ) { return b; } else { return a; }
}
void play_music(const char *music, bool loop = -1)
{
int size;
char *buffer = file_getfilebuffer(music, size);
JA_PlayMusic(JA_LoadMusic((Uint8*)buffer, size, music), loop);
}
void ModuleSequence::doIntro() {
JG_SetUpdateTicks(1000);
JS_LoadMusic("00000003.xm");
JS_PlayMusic(-1);
play_music("00000003.ogg");
JD8_Surface gfx = JD8_LoadSurface( "logo.gif" );
JD8_Palette pal = JD8_LoadPalette( "logo.gif" );
@@ -638,8 +645,7 @@ void ModuleSequence::doSlides() {
const char* arxiu;
if( this->info->num_piramide == 7 ) {
JS_LoadMusic("00000005.xm");
JS_PlayMusic(1);
play_music("00000005.ogg", 1);
if (this->info->diners < 200) {
arxiu = "intro2.gif";
} else {
@@ -700,7 +706,7 @@ void ModuleSequence::doSlides() {
step++;
break;
case 8:
if (this->info->num_piramide != 7) JS_FadeOutMusic();
if (this->info->num_piramide != 7) JA_FadeOutMusic(250);
exit = true;
break;
}
@@ -712,8 +718,7 @@ void ModuleSequence::doSlides() {
}
void ModuleSequence::doBanner() {
JS_LoadMusic("00000004.xm");
JS_PlayMusic(-1);
play_music("00000004.ogg");
this->contador = 5000;
@@ -754,12 +759,11 @@ void ModuleSequence::doBanner() {
if( contador == 0 ) exit = true;
}
}
JS_FadeOutMusic();
JA_FadeOutMusic(250);
}
void ModuleSequence::doSecreta() {
JS_LoadMusic("00000002.xm");
JS_PlayMusic(-1);
play_music("00000002.ogg");
JG_SetUpdateTicks(20);
JD8_FadeOut();
JD8_Surface gfx = JD8_LoadSurface("tomba1.gif");
@@ -834,7 +838,7 @@ void ModuleSequence::doSecreta() {
JD8_FadeOut();
memcpy(pal, pal_aux, 768);
JD8_ClearScreen(255);
JS_FadeOutMusic();
JA_FadeOutMusic(250);
exit = true;
break;
}
@@ -912,8 +916,7 @@ void ModuleSequence::doCredits() {
}
void ModuleSequence::doMort() {
JS_LoadMusic("00000001.xm");
JS_PlayMusic(1);
play_music("00000001.ogg");
JI_DisableKeyboard(60);
@@ -942,7 +945,6 @@ void ModuleSequence::doMort() {
if( contador == 0 ) exit = true;
}
}
JS_LoadMusic("00000003.xm");
JS_PlayMusic(-1);
play_music("00000003.ogg");
}

View File

@@ -1,6 +1,7 @@
#include "prota.h"
#include "jgame.h"
#include "jinput.h"
#include <stdlib.h>
Prota::Prota( JD8_Surface gfx, Info* info ) : Sprite( gfx ) {
this->info = info;

View File

@@ -1,4 +1,5 @@
#include "sprite.h"
#include <stdlib.h>
Sprite::Sprite( JD8_Surface gfx ) {

5584
stb_vorbis.h Normal file

File diff suppressed because it is too large Load Diff