diff --git a/src/game/bettercamera.h b/src/game/bettercamera.h index 2896103..b3355ef 100644 --- a/src/game/bettercamera.h +++ b/src/game/bettercamera.h @@ -29,6 +29,7 @@ enum newcam_flagvalues extern void newcam_display_options(void); extern void newcam_check_pause_buttons(void); extern void newcam_init_settings(void); +extern void newcam_save_settings(void); extern void newcam_render_option_text(void); extern void newcam_diagnostics(void); diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index 92a5402..8ad4cef 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -8,6 +8,7 @@ #include "bettercamera.h" #include "include/text_strings.h" #include "engine/surface_collision.h" +#include "pc/configfile.h" #include @@ -153,28 +154,28 @@ static f32 newcam_clamp(f32 value, f32 max, f32 min) return value; } ///These are the default settings for Puppycam. You may change them to change how they'll be set for first timers. -void newcam_init_settings() +void newcam_init_settings(void) { - if (save_check_firsttime()) - { - save_file_get_setting(); - newcam_clamp(newcam_sensitivityX, 10, 250); - newcam_clamp(newcam_sensitivityY, 10, 250); - newcam_clamp(newcam_aggression, 0, 100); - newcam_clamp(newcam_panlevel, 0, 100); - newcam_clamp(newcam_invertX, 0, 1); - newcam_clamp(newcam_invertY, 0, 1); - } - else - { - newcam_sensitivityX = 75; - newcam_sensitivityY = 75; - newcam_aggression = 0; - newcam_panlevel = 75; - newcam_invertX = 0; - newcam_invertY = 0; - save_set_firsttime(); - } + newcam_sensitivityX = newcam_clamp(configCameraXSens, 10, 250); + newcam_sensitivityY = newcam_clamp(configCameraYSens, 10, 250); + newcam_aggression = newcam_clamp(configCameraAggr, 0, 100); + newcam_panlevel = newcam_clamp(configCameraPan, 0, 100); + newcam_invertX = (u8)configCameraInvertX; + newcam_invertY = (u8)configCameraInvertY; + newcam_mouse = (u8)configCameraMouse; + newcam_analogue = (u8)configEnableCamera; +} + +void newcam_save_settings(void) +{ + configCameraXSens = newcam_sensitivityX; + configCameraYSens = newcam_sensitivityY; + configCameraAggr = newcam_aggression; + configCameraPan = newcam_panlevel; + configCameraInvertX = newcam_invertX != 0; + configCameraInvertY = newcam_invertY != 0; + configEnableCamera = newcam_analogue != 0; + configCameraMouse = newcam_mouse != 0; } /** Mathematic calculations. This stuffs so basic even *I* understand it lol @@ -423,7 +424,7 @@ static void newcam_zoom_button(void) if (newcam_centering && newcam_modeflags & NC_FLAG_XTURN) { newcam_yaw = approach_s16_symmetric(newcam_yaw,newcam_yaw_target,0x800); - if (newcam_yaw = newcam_yaw_target) + if (newcam_yaw == newcam_yaw_target) newcam_centering = 0; } else @@ -505,7 +506,7 @@ static void newcam_collision(void) - find_surface_on_ray(newcam_pos_target, camdir, &surf, &hitpos); + find_surface_on_ray(newcam_pos_target, camdir, &surf, hitpos); if (surf) { @@ -705,11 +706,11 @@ void newcam_change_setting(u8 toggle) case 2: if (newcam_sensitivityX > 10 && newcam_sensitivityX < 250) newcam_sensitivityX += toggle; - break; + break; case 3: if (newcam_sensitivityY > 10 && newcam_sensitivityY < 250) newcam_sensitivityY += toggle; - break; + break; case 4: newcam_invertX ^= 1; break; @@ -719,11 +720,11 @@ void newcam_change_setting(u8 toggle) case 6: if (newcam_aggression > 0 && newcam_aggression < 100) newcam_aggression += toggle; - break; + break; case 7: if (newcam_panlevel > 0 && newcam_panlevel < 100) newcam_panlevel += toggle; - break; + break; } } @@ -826,15 +827,15 @@ void newcam_check_pause_buttons() { if (gPlayer1Controller->buttonPressed & R_TRIG) { - #ifndef nosound - play_sound(SOUND_MENU_CHANGE_SELECT, gDefaultSoundArgs); - #endif + #ifndef nosound + play_sound(SOUND_MENU_CHANGE_SELECT, gDefaultSoundArgs); + #endif if (newcam_option_open == 0) newcam_option_open = 1; else { newcam_option_open = 0; - save_file_set_setting(); + newcam_save_settings(); } } diff --git a/src/game/game_init.c b/src/game/game_init.c index cbf712c..939383a 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -599,6 +599,11 @@ void init_controllers(void) { gControllers[cont++].controllerData = &gControllerPads[port]; } } + +#ifdef BETTERCAMERA + // load bettercam settings from the config file + newcam_init_settings(); +#endif } void setup_game_memory(void) { diff --git a/src/game/save_file.c b/src/game/save_file.c index 6f42973..6803fb6 100644 --- a/src/game/save_file.c +++ b/src/game/save_file.c @@ -11,9 +11,6 @@ #include "level_table.h" #include "course_table.h" #include "thread6.h" -#ifdef BETTERCAMERA -#include "bettercamera.h" -#endif #define MENU_DATA_MAGIC 0x4849 #define SAVE_FILE_MAGIC 0x4441 @@ -568,50 +565,6 @@ u16 save_file_get_sound_mode(void) { return gSaveBuffer.menuData[0].soundMode; } -#ifdef BETTERCAMERA -void save_file_set_setting(void) { - - gSaveBuffer.menuData[0].camx = newcam_sensitivityX; - gSaveBuffer.menuData[0].camy = newcam_sensitivityY; - gSaveBuffer.menuData[0].invertx = newcam_invertX; - gSaveBuffer.menuData[0].inverty = newcam_invertY; - gSaveBuffer.menuData[0].camc = newcam_aggression; - gSaveBuffer.menuData[0].camp = newcam_panlevel; - gSaveBuffer.menuData[0].analogue = newcam_analogue; - - gSaveBuffer.menuData[0].firsttime = 1; - - - gMainMenuDataModified = TRUE; - save_main_menu_data(); -} - -void save_file_get_setting(void) { - newcam_sensitivityX = gSaveBuffer.menuData[0].camx; - newcam_sensitivityY = gSaveBuffer.menuData[0].camy; - newcam_invertX = gSaveBuffer.menuData[0].invertx; - newcam_invertY = gSaveBuffer.menuData[0].inverty; - newcam_aggression = gSaveBuffer.menuData[0].camc; - newcam_panlevel = gSaveBuffer.menuData[0].camp; - newcam_analogue = gSaveBuffer.menuData[0].analogue; - -} - -u8 save_check_firsttime(void) -{ - return gSaveBuffer.menuData[0].firsttime; -} - - -void save_set_firsttime(void) -{ - gSaveBuffer.menuData[0].firsttime = 1; - - gMainMenuDataModified = TRUE; - save_main_menu_data(); -} -#endif - void save_file_move_cap_to_default_location(void) { if (save_file_get_flags() & SAVE_FLAG_CAP_ON_GROUND) { switch (gSaveBuffer.files[gCurrSaveFileNum - 1][0].capLevel) { diff --git a/src/game/save_file.h b/src/game/save_file.h index dca6dc7..198748d 100644 --- a/src/game/save_file.h +++ b/src/game/save_file.h @@ -6,11 +6,7 @@ #include "course_table.h" -#ifndef BETTERCAMERA #define EEPROM_SIZE 0x200 -#else -#define EEPROM_SIZE 0x800 -#endif #define NUM_SAVE_FILES 4 struct SaveBlockSignature @@ -54,16 +50,7 @@ struct MainMenuSaveData // on the high score screen. u32 coinScoreAges[NUM_SAVE_FILES]; u16 soundMode; -#ifdef BETTERCAMERA - u8 camx; - u8 camy; - u8 analogue; - u8 invertx; - u8 inverty; - u8 camc; - u8 camp; - u8 firsttime; -#endif + #ifdef VERSION_EU u16 language; #define SUBTRAHEND 8 @@ -71,11 +58,8 @@ struct MainMenuSaveData #define SUBTRAHEND 6 #endif - // Pad to match the EEPROM size of 0x200 (10 bytes on JP/US, 8 bytes on EU) - #ifndef BETTERCAMERA u8 filler[EEPROM_SIZE / 2 - SUBTRAHEND - NUM_SAVE_FILES * (4 + sizeof(struct SaveFile))]; - #endif struct SaveBlockSignature signature; }; @@ -86,9 +70,6 @@ struct SaveBuffer struct SaveFile files[NUM_SAVE_FILES][2]; // The main menu data has two copies. If one is bad, the other is used as a backup. struct MainMenuSaveData menuData[2]; - #ifdef BETTERCAMERA - u8 filler[1535]; //!I still haven't done an algorithm for this yet lol - #endif }; struct WarpNode; @@ -163,12 +144,6 @@ s32 save_file_get_cap_pos(Vec3s capPos); void save_file_set_sound_mode(u16 mode); u16 save_file_get_sound_mode(void); void save_file_move_cap_to_default_location(void); -#ifdef BETTERCAMERA -void save_set_firsttime(void); -u8 save_check_firsttime(void); -void save_file_get_setting(void); -void save_file_set_setting(void); -#endif void disable_warp_checkpoint(void); void check_if_should_set_warp_checkpoint(struct WarpNode *a); diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 57b9a4f..4d38aaa 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -58,35 +58,55 @@ unsigned int configMouseB = 1; unsigned int configMouseL = 4; unsigned int configMouseR = 5; unsigned int configMouseZ = 2; - +#ifdef BETTERCAMERA +// BetterCamera settings +unsigned int configCameraXSens = 50; +unsigned int configCameraYSens = 50; +unsigned int configCameraAggr = 0; +unsigned int configCameraPan = 0; +bool configCameraInvertX = false; +bool configCameraInvertY = false; +bool configEnableCamera = false; +bool configCameraMouse = false; +#endif static const struct ConfigOption options[] = { - {.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configFullscreen}, - {.name = "key_a", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyA}, - {.name = "key_b", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyB}, - {.name = "key_start", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStart}, - {.name = "key_l", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyL}, - {.name = "key_r", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyR}, - {.name = "key_z", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyZ}, - {.name = "key_cup", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyCUp}, - {.name = "key_cdown", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyCDown}, - {.name = "key_cleft", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyCLeft}, - {.name = "key_cright", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyCRight}, - {.name = "key_stickup", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickUp}, - {.name = "key_stickdown", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickDown}, - {.name = "key_stickleft", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickLeft}, - {.name = "key_stickright", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickRight}, - {.name = "joy_a", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyA}, - {.name = "joy_b", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyB}, - {.name = "joy_start", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyStart}, - {.name = "joy_l", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyL}, - {.name = "joy_r", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyR}, - {.name = "joy_z", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyZ}, - {.name = "mouse_a", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseA}, - {.name = "mouse_b", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseB}, - {.name = "mouse_l", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseL}, - {.name = "mouse_r", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseR}, - {.name = "mouse_z", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseZ}, + {.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configFullscreen}, + {.name = "key_a", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyA}, + {.name = "key_b", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyB}, + {.name = "key_start", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStart}, + {.name = "key_l", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyL}, + {.name = "key_r", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyR}, + {.name = "key_z", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyZ}, + {.name = "key_cup", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyCUp}, + {.name = "key_cdown", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyCDown}, + {.name = "key_cleft", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyCLeft}, + {.name = "key_cright", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyCRight}, + {.name = "key_stickup", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickUp}, + {.name = "key_stickdown", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickDown}, + {.name = "key_stickleft", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickLeft}, + {.name = "key_stickright", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickRight}, + {.name = "joy_a", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyA}, + {.name = "joy_b", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyB}, + {.name = "joy_start", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyStart}, + {.name = "joy_l", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyL}, + {.name = "joy_r", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyR}, + {.name = "joy_z", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyZ}, + {.name = "mouse_a", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseA}, + {.name = "mouse_b", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseB}, + {.name = "mouse_l", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseL}, + {.name = "mouse_r", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseR}, + {.name = "mouse_z", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseZ}, + #ifdef BETTERCAMERA + {.name = "bettercam_enable", .type = CONFIG_TYPE_BOOL, .boolValue = &configEnableCamera}, + {.name = "bettercam_mouse_look", .type = CONFIG_TYPE_BOOL, .boolValue = &configCameraMouse}, + {.name = "bettercam_invertx", .type = CONFIG_TYPE_BOOL, .boolValue = &configCameraInvertX}, + {.name = "bettercam_inverty", .type = CONFIG_TYPE_BOOL, .boolValue = &configCameraInvertY}, + {.name = "bettercam_xsens", .type = CONFIG_TYPE_UINT, .uintValue = &configCameraXSens}, + {.name = "bettercam_ysens", .type = CONFIG_TYPE_UINT, .uintValue = &configCameraYSens}, + {.name = "bettercam_aggression", .type = CONFIG_TYPE_UINT, .uintValue = &configCameraAggr}, + {.name = "bettercam_pan_level", .type = CONFIG_TYPE_UINT, .uintValue = &configCameraPan}, + #endif }; // Reads an entire line from a file (excluding the newline character) and returns an allocated string diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 1796816..a2044dd 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -1,6 +1,10 @@ #ifndef CONFIGFILE_H #define CONFIGFILE_H +#include + +#define CONFIG_FILE "sm64config.txt" + extern bool configFullscreen; extern unsigned int configKeyA; extern unsigned int configKeyB; @@ -28,6 +32,16 @@ extern unsigned int configMouseStart; extern unsigned int configMouseL; extern unsigned int configMouseR; extern unsigned int configMouseZ; +#ifdef BETTERCAMERA +extern unsigned int configCameraXSens; +extern unsigned int configCameraYSens; +extern unsigned int configCameraAggr; +extern unsigned int configCameraPan; +extern bool configCameraInvertX; +extern bool configCameraInvertY; +extern bool configEnableCamera; +extern bool configCameraMouse; +#endif void configfile_load(const char *filename); void configfile_save(const char *filename); diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 07a5169..5b4bcd2 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -20,8 +20,6 @@ #include "configfile.h" -#define CONFIG_FILE "sm64config.txt" - OSMesg D_80339BEC; OSMesgQueue gSIEventMesgQueue;