Skip to content

Commit

Permalink
hidden entries test for menu sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
xesf committed Oct 20, 2024
1 parent 61b2bbc commit 48bc668
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
15 changes: 13 additions & 2 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define HQR_PALETTE_MENU 5
#define HQR_RESSOURCE "RESSOURC.HQR"

#define HQR_MENU_SAMPLES 2

#define HQR_SCREEN_ADELINE 34
#define HQR_SCREEN_TIMECO 38
#define HQR_SCREEN_MENU 42
Expand Down Expand Up @@ -49,7 +51,6 @@ void game_image(state_t *state, u32 index, u32 delay, i32 fade_in) {
}

void game_introduction() {

sample_play(3, 22050, 0, 0);
game_image(state, HQR_SCREEN_ADELINE, 6000, FALSE);

Expand All @@ -66,7 +67,7 @@ void game_introduction() {
}

game_image(state, HQR_SCREEN_TIMECO, 6000, TRUE);
sample_stop_all();
// sample_stop_all();

switch(state->game_type) {
case TIMECO_DEMO:
Expand All @@ -80,6 +81,16 @@ void game_introduction() {

// then menu > new game > then timewrap acf
game_image(state, HQR_SCREEN_MENU, 0, TRUE);

u8 *menu_samples = NULL;
if (!hqr_get_entry_alloc(&menu_samples, HQR_RESSOURCE, HQR_MENU_SAMPLES)) {
printf("Error: Couldn't load palette %d\n", HQR_MENU_SAMPLES);
}
i32 sample_hidden_index = 0;
u8 *sample_ptr = NULL;
u32 entry_size = hqr_get_hidden_entry_ptr(&sample_ptr, menu_samples, 0);

sample_play_ptr(HQR_MENU_SAMPLES * 100 + sample_hidden_index, sample_ptr, entry_size, 22050, 0, 0);
}

void game_release(state_t *state) {
Expand Down
22 changes: 15 additions & 7 deletions src/lib/hqr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include "hqr.h"
#include "file_reader.h"

typedef struct hqr_hidden_entry_s {
#pragma pack(1)
typedef struct {
u32 size_file;
u32 compressed_size;
i16 compress_type;
Expand Down Expand Up @@ -197,10 +198,11 @@ i32 hqr_get_entry_alloc(u8 ** ptr, c8 *filename, i32 index) {
return size;
}

i32 hqr_get_hidden_entry_ptr(u8 *entry_ptr, void *hqr_ptr, i32 index)
{
i32 hqr_get_hidden_entry_ptr(u8 **entry_ptr, u8 *hqr_ptr, i32 index) {
u32 num_hidden_entries;
u32 offset;
u32 entry_size;
u8 *ptr;

num_hidden_entries = *(u32*)hqr_ptr / 4;

Expand All @@ -210,10 +212,16 @@ i32 hqr_get_hidden_entry_ptr(u8 *entry_ptr, void *hqr_ptr, i32 index)
return 0;
}

entry_ptr = (u8*)hqr_ptr + index * 4;
offset = *(u32*)entry_ptr;
ptr = hqr_ptr + index * 4;
offset = *(u32*)ptr;

entry_ptr = (u8*)hqr_ptr + offset + sizeof(hqr_hidden_entry_t);
entry_size = *(u32*)(hqr_ptr + offset);
*entry_ptr = (u8*)malloc(entry_size * sizeof(u8));
if (!*entry_ptr) {
printf("HQR WARNING: unable to allocate entry memory!!\n");
return 0;
}
memcpy(*entry_ptr, hqr_ptr + offset + sizeof(hqr_hidden_entry_t), entry_size);

return 1;
return entry_size;
}
2 changes: 1 addition & 1 deletion src/lib/hqr.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ i32 hqr_get_num_entries(c8 *filename);
i32 hqr_get_entry(u8 * ptr, c8 *filename, i32 index);
i32 hqr_get_entry_size(c8 *filename, i32 index);
i32 hqr_get_entry_alloc(u8 ** ptr, c8 *filename, i32 index);
i32 hqr_get_hidden_entry_ptr(u8 *entry_ptr, void *hqr_ptr, i32 index);
i32 hqr_get_hidden_entry_ptr(u8 **entry_ptr, u8 *hqr_ptr, i32 index);

#endif
21 changes: 11 additions & 10 deletions src/sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,22 @@ void sample_set_position(i32 channel_index, i32 x, i32 y, i32 z, i32 hero_x, i32
}

void sample_play(i32 index, i32 frequency, i32 repeat, i32 pan) {
sample_play_position(index, frequency, repeat, 0, 0, 0, -1, 0, 0, 0);
i32 sample_size = 0;
u8* sample_ptr;
sample_size = hqr_get_entry_alloc(&sample_ptr, HQR_RESOURCE, index);
sample_play_position(index, sample_ptr, sample_size, frequency, repeat, 0, 0, 0, -1, 0, 0, 0);
}

void sample_play_ptr(i32 index, u8* sample_ptr, i32 sample_size, i32 frequency, i32 repeat, i32 pan) {
sample_play_position(index, sample_ptr, sample_size, frequency, repeat, 0, 0, 0, -1, 0, 0, 0);
}

void sample_play_position(i32 index, i32 frequency, i32 repeat, i32 x, i32 y, i32 z, i32 actor_index, i32 hero_x, i32 hero_y, i32 hero_z) {
void sample_play_position(i32 index, u8* sample_ptr, i32 sample_size, i32 frequency, i32 repeat, i32 x, i32 y, i32 z, i32 actor_index, i32 hero_x, i32 hero_y, i32 hero_z) {
if (!config_file.sample) {
return;
}

i32 sampSize = 0;
i32 channel_index = -1;
u8* sample_ptr;

sampSize = hqr_get_entry_alloc(&sample_ptr, HQR_RESOURCE, index);

channel_index = sample_free_channel_index();
i32 channel_index = sample_free_channel_index();

if (channel_index != -1) {
samples.playing[channel_index] = index;
Expand All @@ -67,7 +68,7 @@ void sample_play_position(i32 index, i32 frequency, i32 repeat, i32 x, i32 y, i3
samples.actors[channel_index] = actor_index;
}

if (system_mixer_play(sample_ptr, sampSize, channel_index, repeat) == -1)
if (system_mixer_play(sample_ptr, sample_size, channel_index, repeat) == -1)
printf("Error while playing Sample %d \n", index);
}

Expand Down
3 changes: 2 additions & 1 deletion src/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ void sample_init();
i32 sample_is_playing(i32 index);

void sample_play(i32 index, i32 frequency, i32 repeat, i32 pan);
void sample_play_position(i32 index, i32 frequency, i32 repeat, i32 x, i32 y, i32 z, i32 actor_index, i32 hero_x, i32 hero_y, i32 hero_z);
void sample_play_ptr(i32 index, u8* sample_ptr, i32 sample_size, i32 frequency, i32 repeat, i32 pan);
void sample_play_position(i32 index, u8* sample_ptr, i32 sample_size, i32 frequency, i32 repeat, i32 x, i32 y, i32 z, i32 actor_index, i32 hero_x, i32 hero_y, i32 hero_z);
void sample_pause();
void sample_resume();
void sample_stop_all();
Expand Down

0 comments on commit 48bc668

Please sign in to comment.