Skip to content

Commit

Permalink
Fix variable naming again
Browse files Browse the repository at this point in the history
  • Loading branch information
bvschaik committed Apr 28, 2018
1 parent 584a15f commit 2990585
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 141 deletions.
88 changes: 44 additions & 44 deletions platform/SDLSoundDevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static struct {
unsigned char *data;
int cur;
int len;
} customMusic;
} custom_music;


static int percentage_to_volume(int percentage)
Expand Down Expand Up @@ -54,14 +54,14 @@ void sound_device_close()
}
}

void sound_device_init_channels(int numChannels, const char filenames[][CHANNEL_FILENAME_MAX])
void sound_device_init_channels(int num_channels, const char filenames[][CHANNEL_FILENAME_MAX])
{
if (initialized) {
if (numChannels > MAX_CHANNELS) {
numChannels = MAX_CHANNELS;
if (num_channels > MAX_CHANNELS) {
num_channels = MAX_CHANNELS;
}
Mix_AllocateChannels(numChannels);
for (int i = 0; i < numChannels; i++) {
Mix_AllocateChannels(num_channels);
for (int i = 0; i < num_channels; i++) {
if (filenames[i][0]) {
channels[i] = Mix_LoadWAV(filenames[i]);
}
Expand All @@ -79,22 +79,22 @@ int sound_device_is_channel_playing(int channel)
return Mix_Playing(channel);
}

void sound_device_set_music_volume(int volumePercentage)
void sound_device_set_music_volume(int volume_percentage)
{
Mix_VolumeMusic(percentage_to_volume(volumePercentage));
Mix_VolumeMusic(percentage_to_volume(volume_percentage));
}

void sound_device_set_channel_volume(int channel, int volumePercentage)
void sound_device_set_channel_volume(int channel, int volume_percentage)
{
if (channels[channel]) {
Mix_VolumeChunk(channels[channel], percentage_to_volume(volumePercentage));
Mix_VolumeChunk(channels[channel], percentage_to_volume(volume_percentage));
}
}

void sound_device_set_channel_panning(int channel, int leftPct, int rightPct)
void sound_device_set_channel_panning(int channel, int left_pct, int right_pct)
{
if (channels[channel]) {
Mix_SetPanning(channel, leftPct * 255 / 100, rightPct * 255 / 100);
Mix_SetPanning(channel, left_pct * 255 / 100, right_pct * 255 / 100);
}
}

Expand Down Expand Up @@ -160,45 +160,45 @@ void sound_device_stop_channel(int channel)

static int next_audio_frame()
{
if (customMusic.data) {
free(customMusic.data);
customMusic.data = 0;
if (custom_music.data) {
free(custom_music.data);
custom_music.data = 0;
}

int audioLen;
const unsigned char *data = customMusic.callback(&audioLen);
if (!data || audioLen <= 0) {
int audio_len;
const unsigned char *data = custom_music.callback(&audio_len);
if (!data || audio_len <= 0) {
return 0;
}

if (audioLen > 0) {
if (audio_len > 0) {
// convert audio to SDL format
customMusic.cvt.buf = (Uint8*) malloc(audioLen * customMusic.cvt.len_mult);
customMusic.cvt.len = audioLen;
memcpy(customMusic.cvt.buf, data, audioLen);
SDL_ConvertAudio(&customMusic.cvt);
customMusic.cur = 0;
customMusic.len = customMusic.cvt.len_cvt;
customMusic.data = customMusic.cvt.buf;
customMusic.cvt.buf = 0;
customMusic.cvt.len = 0;
custom_music.cvt.buf = (Uint8*) malloc(audio_len * custom_music.cvt.len_mult);
custom_music.cvt.len = audio_len;
memcpy(custom_music.cvt.buf, data, audio_len);
SDL_ConvertAudio(&custom_music.cvt);
custom_music.cur = 0;
custom_music.len = custom_music.cvt.len_cvt;
custom_music.data = custom_music.cvt.buf;
custom_music.cvt.buf = 0;
custom_music.cvt.len = 0;
}
return audioLen;
return audio_len;
}

static int copy_audio_from_buffer(Uint8 *stream, int len)
{
if (!customMusic.data || customMusic.cur >= customMusic.len) {
if (!custom_music.data || custom_music.cur >= custom_music.len) {
return 0;
}
// push existing bytes
int toWrite = customMusic.len - customMusic.cur;
if (toWrite > len) {
toWrite = len;
int to_write = custom_music.len - custom_music.cur;
if (to_write > len) {
to_write = len;
}
memcpy(stream, &customMusic.data[customMusic.cur], toWrite);
customMusic.cur += toWrite;
return toWrite;
memcpy(stream, &custom_music.data[custom_music.cur], to_write);
custom_music.cur += to_write;
return to_write;
}

static void custom_music_callback(void *dummy, Uint8 *stream, int len)
Expand All @@ -222,20 +222,20 @@ static void custom_music_callback(void *dummy, Uint8 *stream, int len)
}
}

void sound_device_use_custom_music_player(int bitdepth, int channels, int rate, const unsigned char *(*callback)(int *outLen))
void sound_device_use_custom_music_player(int bitdepth, int channels, int rate, const unsigned char *(*callback)(int *out_len))
{
SDL_BuildAudioCVT(&customMusic.cvt, bitdepth, channels, rate, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_RATE);
customMusic.callback = callback;
SDL_BuildAudioCVT(&custom_music.cvt, bitdepth, channels, rate, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_RATE);
custom_music.callback = callback;
Mix_HookMusic(custom_music_callback, 0);
}

void sound_device_use_default_music_player()
{
if (customMusic.data) {
free(customMusic.data);
customMusic.data = 0;
customMusic.len = 0;
customMusic.cur = 0;
if (custom_music.data) {
free(custom_music.data);
custom_music.data = 0;
custom_music.len = 0;
custom_music.cur = 0;
}
Mix_HookMusic(0, 0);
}
32 changes: 16 additions & 16 deletions src/game/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,27 @@ static void load_settings(buffer *buf)
buffer_skip(buf, 6);
data.game_speed = buffer_read_i32(buf);
data.scroll_speed = buffer_read_i32(buf);
buffer_skip(buf, 32); //uint8_t playerName[32];
buffer_skip(buf, 32); //uint8_t player_name[32];
buffer_skip(buf, 16);
data.last_advisor = buffer_read_i32(buf);
buffer_skip(buf, 4); //int saveGameMissionId;
buffer_skip(buf, 4); //int save_game_mission_id;
data.tooltips = buffer_read_i32(buf);
buffer_skip(buf, 4); //int startingFavor;
buffer_skip(buf, 4); //int personalSavingsLastMission;
buffer_skip(buf, 4); //int currentMissionId;
buffer_skip(buf, 4); //int isCustomScenario;
buffer_skip(buf, 4); //int starting_favor;
buffer_skip(buf, 4); //int personal_savings_last_mission;
buffer_skip(buf, 4); //int current_mission_id;
buffer_skip(buf, 4); //int is_custom_scenario;
data.sound_city.enabled = buffer_read_u8(buf);
data.warnings = buffer_read_u8(buf);
data.monthly_autosave = buffer_read_u8(buf);
buffer_skip(buf, 1); //unsigned char autoclearEnabled;
buffer_skip(buf, 1); //unsigned char autoclear_enabled;
data.sound_effects.volume = buffer_read_i32(buf);
data.sound_music.volume = buffer_read_i32(buf);
data.sound_speech.volume = buffer_read_i32(buf);
data.sound_city.volume = buffer_read_i32(buf);
buffer_skip(buf, 8); // ram
data.window_width = buffer_read_i32(buf);
data.window_height = buffer_read_i32(buf);
buffer_skip(buf, 8); //int maxConfirmedResolution;
buffer_skip(buf, 8); //int max_confirmed_resolution;
for (int i = 0; i < MAX_PERSONAL_SAVINGS; i++) {
data.personal_savings[i] = buffer_read_i32(buf);
}
Expand Down Expand Up @@ -138,27 +138,27 @@ void settings_save()
buffer_skip(buf, 6);
buffer_write_i32(buf, data.game_speed);
buffer_write_i32(buf, data.scroll_speed);
buffer_skip(buf, 32); //uint8_t playerName[32];
buffer_skip(buf, 32); //uint8_t player_name[32];
buffer_skip(buf, 16);
buffer_write_i32(buf, data.last_advisor);
buffer_skip(buf, 4); //int saveGameMissionId;
buffer_skip(buf, 4); //int save_game_mission_id;
buffer_write_i32(buf, data.tooltips);
buffer_skip(buf, 4); //int startingFavor;
buffer_skip(buf, 4); //int personalSavingsLastMission;
buffer_skip(buf, 4); //int currentMissionId;
buffer_skip(buf, 4); //int isCustomScenario;
buffer_skip(buf, 4); //int starting_favor;
buffer_skip(buf, 4); //int personal_savings_last_mission;
buffer_skip(buf, 4); //int current_mission_id;
buffer_skip(buf, 4); //int is_custom_scenario;
buffer_write_u8(buf, data.sound_city.enabled);
buffer_write_u8(buf, data.warnings);
buffer_write_u8(buf, data.monthly_autosave);
buffer_skip(buf, 1); //unsigned char autoclearEnabled;
buffer_skip(buf, 1); //unsigned char autoclear_enabled;
buffer_write_i32(buf, data.sound_effects.volume);
buffer_write_i32(buf, data.sound_music.volume);
buffer_write_i32(buf, data.sound_speech.volume);
buffer_write_i32(buf, data.sound_city.volume);
buffer_skip(buf, 8); // ram
buffer_write_i32(buf, data.window_width);
buffer_write_i32(buf, data.window_height);
buffer_skip(buf, 8); //int maxConfirmedResolution;
buffer_skip(buf, 8); //int max_confirmed_resolution;
for (int i = 0; i < MAX_PERSONAL_SAVINGS; i++) {
buffer_write_i32(buf, data.personal_savings[i]);
}
Expand Down
58 changes: 29 additions & 29 deletions src/graphics/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,67 +103,67 @@ void graphics_reset_clip_rectangle()

static void set_clip_x(int x_offset, int width)
{
clip.clippedPixelsLeft = 0;
clip.clippedPixelsRight = 0;
clip.clipped_pixels_left = 0;
clip.clipped_pixels_right = 0;
if (width <= 0
|| x_offset + width <= clip_rectangle.x_start
|| x_offset >= clip_rectangle.x_end) {
clip.clipX = CLIP_INVISIBLE;
clip.visiblePixelsX = 0;
clip.clip_x = CLIP_INVISIBLE;
clip.visible_pixels_x = 0;
return;
}
if (x_offset < clip_rectangle.x_start) {
// clipped on the left
clip.clippedPixelsLeft = clip_rectangle.x_start - x_offset;
clip.clipped_pixels_left = clip_rectangle.x_start - x_offset;
if (x_offset + width <= clip_rectangle.x_end) {
clip.clipX = CLIP_LEFT;
clip.clip_x = CLIP_LEFT;
} else {
clip.clipX = CLIP_BOTH;
clip.clippedPixelsRight = x_offset + width - clip_rectangle.x_end;
clip.clip_x = CLIP_BOTH;
clip.clipped_pixels_right = x_offset + width - clip_rectangle.x_end;
}
} else if (x_offset + width > clip_rectangle.x_end) {
clip.clipX = CLIP_RIGHT;
clip.clippedPixelsRight = x_offset + width - clip_rectangle.x_end;
clip.clip_x = CLIP_RIGHT;
clip.clipped_pixels_right = x_offset + width - clip_rectangle.x_end;
} else {
clip.clipX = CLIP_NONE;
clip.clip_x = CLIP_NONE;
}
clip.visiblePixelsX = width - clip.clippedPixelsLeft - clip.clippedPixelsRight;
clip.visible_pixels_x = width - clip.clipped_pixels_left - clip.clipped_pixels_right;
}

static void set_clip_y(int y_offset, int height)
{
clip.clippedPixelsTop = 0;
clip.clippedPixelsBottom = 0;
clip.clipped_pixels_top = 0;
clip.clipped_pixels_bottom = 0;
if (height <= 0
|| y_offset + height <= clip_rectangle.y_start
|| y_offset >= clip_rectangle.y_end) {
clip.clipY = CLIP_INVISIBLE;
clip.clip_y = CLIP_INVISIBLE;
} else if (y_offset < clip_rectangle.y_start) {
// clipped on the top
clip.clippedPixelsTop = clip_rectangle.y_start - y_offset;
clip.clipped_pixels_top = clip_rectangle.y_start - y_offset;
if (y_offset + height <= clip_rectangle.y_end) {
clip.clipY = CLIP_TOP;
clip.clip_y = CLIP_TOP;
} else {
clip.clipY = CLIP_BOTH;
clip.clippedPixelsBottom = y_offset + height - clip_rectangle.y_end;
clip.clip_y = CLIP_BOTH;
clip.clipped_pixels_bottom = y_offset + height - clip_rectangle.y_end;
}
} else if (y_offset + height > clip_rectangle.y_end) {
clip.clipY = CLIP_BOTTOM;
clip.clippedPixelsBottom = y_offset + height - clip_rectangle.y_end;
clip.clip_y = CLIP_BOTTOM;
clip.clipped_pixels_bottom = y_offset + height - clip_rectangle.y_end;
} else {
clip.clipY = CLIP_NONE;
clip.clip_y = CLIP_NONE;
}
clip.visiblePixelsY = height - clip.clippedPixelsTop - clip.clippedPixelsBottom;
clip.visible_pixels_y = height - clip.clipped_pixels_top - clip.clipped_pixels_bottom;
}

const clip_info *graphics_get_clip_info(int x, int y, int width, int height)
{
set_clip_x(x, width);
set_clip_y(y, height);
if (clip.clipX == CLIP_INVISIBLE || clip.clipY == CLIP_INVISIBLE) {
clip.isVisible = 0;
if (clip.clip_x == CLIP_INVISIBLE || clip.clip_y == CLIP_INVISIBLE) {
clip.is_visible = 0;
} else {
clip.isVisible = 1;
clip.is_visible = 1;
}
return &clip;
}
Expand Down Expand Up @@ -246,11 +246,11 @@ void graphics_fill_rect(int x, int y, int width, int height, color_t color)
void graphics_shade_rect(int x, int y, int width, int height, int darkness)
{
const clip_info *clip = graphics_get_clip_info(x, y, width, height);
if (!clip->isVisible) {
if (!clip->is_visible) {
return;
}
for (int yy = y + clip->clippedPixelsTop; yy < y + height - clip->clippedPixelsBottom; yy++) {
for (int xx = x + clip->clippedPixelsLeft; xx < x + width - clip->clippedPixelsRight; xx++) {
for (int yy = y + clip->clipped_pixels_top; yy < y + height - clip->clipped_pixels_bottom; yy++) {
for (int xx = x + clip->clipped_pixels_left; xx < x + width - clip->clipped_pixels_right; xx++) {
color_t *pixel = graphics_get_pixel(xx, yy);
int r = (*pixel & 0xff0000) >> 16;
int g = (*pixel & 0xff00) >> 8;
Expand Down
18 changes: 9 additions & 9 deletions src/graphics/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ typedef enum {
} clip_code;

typedef struct {
clip_code clipX;
clip_code clipY;
int clippedPixelsLeft;
int clippedPixelsRight;
int clippedPixelsTop;
int clippedPixelsBottom;
int visiblePixelsX;
int visiblePixelsY;
int isVisible;
clip_code clip_x;
clip_code clip_y;
int clipped_pixels_left;
int clipped_pixels_right;
int clipped_pixels_top;
int clipped_pixels_bottom;
int visible_pixels_x;
int visible_pixels_y;
int is_visible;
} clip_info;

void graphics_init_canvas(int width, int height);
Expand Down
Loading

0 comments on commit 2990585

Please sign in to comment.