old_menu.c (7897B)
1 #include <PR/ultratypes.h> 2 #include <stdio.h> 3 4 #include "debug_utils.h" 5 #include "dynlist_proc.h" 6 #include "gd_types.h" 7 #include "macros.h" 8 #include "objects.h" 9 #include "old_menu.h" 10 #include "renderer.h" 11 12 /** 13 * @file old_menu.c 14 * 15 * This file contains remnants of code for rendering what appears to be a GUI 16 * that used the IRIX Graphics Library, from when this program was a standalone demo. 17 * It also contains code for creating labels and gadget, which are `GdObj`s that 18 * allow for displaying text and memory values on screen. Those `GdObj`s are not 19 * created in-game, but there are some functions in `renderer.c` that use 20 * them, and those functions may still work if called. 21 */ 22 23 // bss 24 static char sDefSettingsMenuStr[0x100]; 25 static struct GdVec3f sStaticVec; 26 UNUSED static struct GdVec3f unusedVec; 27 static struct ObjGadget *sCurGadgetPtr; 28 29 // forward declarations 30 static void reset_gadget_default(struct ObjGadget *); 31 32 /* 239EC0 -> 239F78 */ 33 void get_objvalue(union ObjVarVal *dst, enum ValPtrType type, void *base, size_t offset) { 34 union ObjVarVal *objAddr = (void *) ((u8 *) base + offset); 35 36 switch (type) { 37 case OBJ_VALUE_INT: 38 dst->i = objAddr->i; 39 break; 40 case OBJ_VALUE_FLOAT: 41 dst->f = objAddr->f; 42 break; 43 default: 44 fatal_printf("%s: Undefined ValueType", "get_objvalue"); 45 } 46 } 47 48 /* 239F78 -> 23A00C */ 49 void Unknown8018B7A8(void *a0) { 50 struct GdVec3f sp1C; 51 52 set_cur_dynobj(a0); 53 d_get_init_pos(&sp1C); 54 55 sp1C.x += sStaticVec.x; 56 sp1C.y += sStaticVec.y; 57 sp1C.z += sStaticVec.z; 58 d_set_world_pos(sp1C.x, sp1C.y, sp1C.z); 59 } 60 61 /** 62 * Unused - called when an item is selected from the "Default Settings" menu. 63 * 64 * @param itemId ID of the menu item that was clicked 65 */ 66 static void menu_cb_default_settings(intptr_t itemId) { 67 struct ObjGroup *group = (struct ObjGroup *)itemId; // Unpack pointer from menu item ID 68 apply_to_obj_types_in_group(OBJ_TYPE_GADGETS, (applyproc_t) reset_gadget_default, group); 69 apply_to_obj_types_in_group(OBJ_TYPE_VIEWS, (applyproc_t) stub_renderer_6, gGdViewsGroup); 70 } 71 72 /** 73 * Unused - appends a menu item for the group to sDefSettingsMenuStr. 74 */ 75 static void add_item_to_default_settings_menu(struct ObjGroup *group) { 76 char buf[0x100]; 77 78 if (group->debugPrint == 1) { 79 // Convert pointer to integer and store it as the menu item ID. 80 sprintf(buf, "| %s %%x%d", group->name, (u32) (intptr_t) group); 81 gd_strcat(sDefSettingsMenuStr, buf); 82 } 83 } 84 85 /** 86 * Unused - creates a popup menu that allows the user to control some settings. 87 */ 88 long create_gui_menu(struct ObjGroup *grp) { 89 long dynamicsMenuId; 90 long defaultSettingMenuId; 91 long contTypeMenuId; 92 93 gd_strcpy(sDefSettingsMenuStr, "Default Settings %t %F"); 94 apply_to_obj_types_in_group(OBJ_TYPE_GROUPS, (applyproc_t) add_item_to_default_settings_menu, grp); 95 defaultSettingMenuId = defpup(sDefSettingsMenuStr, &menu_cb_default_settings); 96 97 contTypeMenuId = defpup( 98 "Control Type %t %F" 99 "| U-64 Analogue Joystick %x1 " 100 "| Keyboard %x2 " 101 "| Mouse %x3", 102 &menu_cb_control_type); 103 104 dynamicsMenuId = defpup( 105 "Dynamics %t " 106 "|\t\t\tReset Positions %f " 107 "|\t\t\tSet Defaults %m " 108 "|\t\t\tSet Controller %m " 109 "|\t\t\tRe-Calibrate Controller %f " 110 "|\t\t\tQuit %f", 111 &menu_cb_reset_positions, defaultSettingMenuId, contTypeMenuId, &menu_cb_recalibrate_controller, &gd_exit); 112 113 return dynamicsMenuId; 114 } 115 116 /* 23A190 -> 23A250 */ 117 struct ObjLabel *make_label(struct ObjValPtr *ptr, char *str, s32 a2, f32 x, f32 y, f32 z) { 118 struct ObjLabel *label = (struct ObjLabel *) make_object(OBJ_TYPE_LABELS); 119 label->valfn = NULL; 120 label->valptr = ptr; 121 label->fmtstr = str; 122 label->unk24 = a2; 123 label->unk30 = 4; 124 label->position.x = x; 125 label->position.y = y; 126 label->position.z = z; 127 128 return label; 129 } 130 131 /* 23A250 -> 23A32C */ 132 struct ObjGadget *make_gadget(UNUSED s32 a0, s32 a1) { 133 struct ObjGadget *gdgt = (struct ObjGadget *) make_object(OBJ_TYPE_GADGETS); 134 gdgt->valueGrp = NULL; 135 gdgt->rangeMax = 1.0f; 136 gdgt->rangeMin = 0.0f; 137 gdgt->unk20 = a1; 138 gdgt->colourNum = 0; 139 gdgt->sliderPos = 1.0f; 140 gdgt->size.x = 100.0f; 141 gdgt->size.y = 10.0f; 142 gdgt->size.z = 10.0f; // how is this useful? 143 144 return gdgt; 145 } 146 147 /* 23A32C -> 23A3E4 */ 148 void set_objvalue(union ObjVarVal *src, enum ValPtrType type, void *base, size_t offset) { 149 union ObjVarVal *dst = (void *) ((u8 *) base + offset); 150 switch (type) { 151 case OBJ_VALUE_INT: 152 dst->i = src->i; 153 break; 154 case OBJ_VALUE_FLOAT: 155 dst->f = src->f; 156 break; 157 default: 158 fatal_printf("%s: Undefined ValueType", "set_objvalue"); 159 } 160 } 161 162 /* 23A3E4 -> 23A488; orig name: Unknown8018BD54 */ 163 void set_static_gdgt_value(struct ObjValPtr *vp) { 164 switch (vp->datatype) { 165 case OBJ_VALUE_FLOAT: 166 set_objvalue(&sCurGadgetPtr->varval, OBJ_VALUE_FLOAT, vp->obj, vp->offset); 167 break; 168 case OBJ_VALUE_INT: 169 set_objvalue(&sCurGadgetPtr->varval, OBJ_VALUE_INT, vp->obj, vp->offset); 170 break; 171 } 172 } 173 174 /* 23A488 -> 23A4D0 */ 175 static void reset_gadget_default(struct ObjGadget *gdgt) { 176 UNUSED u8 filler[4]; 177 178 sCurGadgetPtr = gdgt; 179 apply_to_obj_types_in_group(OBJ_TYPE_VALPTRS, (applyproc_t) set_static_gdgt_value, gdgt->valueGrp); 180 } 181 182 /* 23A4D0 -> 23A784 */ 183 void adjust_gadget(struct ObjGadget *gdgt, s32 a1, s32 a2) { 184 UNUSED u8 filler[8]; 185 f32 range; 186 struct ObjValPtr *vp; 187 188 if (gdgt->type == 1) { 189 gdgt->sliderPos += a2 * (-sCurrentMoveCamera->unk40.z * 1.0E-5); 190 } else if (gdgt->type == 2) { 191 gdgt->sliderPos += a1 * (-sCurrentMoveCamera->unk40.z * 1.0E-5); 192 } 193 194 // slider position must be between 0 and 1 (inclusive) 195 if (gdgt->sliderPos < 0.0f) { 196 gdgt->sliderPos = 0.0f; 197 } else if (gdgt->sliderPos > 1.0f) { 198 gdgt->sliderPos = 1.0f; 199 } 200 201 range = gdgt->rangeMax - gdgt->rangeMin; 202 203 if (gdgt->valueGrp != NULL) { 204 vp = (struct ObjValPtr *) gdgt->valueGrp->firstMember->obj; 205 206 switch (vp->datatype) { 207 case OBJ_VALUE_FLOAT: 208 gdgt->varval.f = gdgt->sliderPos * range + gdgt->rangeMin; 209 break; 210 case OBJ_VALUE_INT: 211 gdgt->varval.i = ((s32)(gdgt->sliderPos * range)) + gdgt->rangeMin; 212 break; 213 default: 214 fatal_printf("%s: Undefined ValueType", "adjust_gadget"); 215 } 216 } 217 218 reset_gadget_default(gdgt); 219 } 220 221 /* 23A784 -> 23A940; orig name: Unknown8018BFB4 */ 222 void reset_gadget(struct ObjGadget *gdgt) { 223 UNUSED u8 filler[8]; 224 f32 range; 225 struct ObjValPtr *vp; 226 227 if (gdgt->rangeMax - gdgt->rangeMin == 0.0f) { 228 fatal_printf("gadget has zero range (%f -> %f)\n", gdgt->rangeMin, gdgt->rangeMax); 229 } 230 231 range = (f32)(1.0 / (gdgt->rangeMax - gdgt->rangeMin)); 232 233 if (gdgt->valueGrp != NULL) { 234 vp = (struct ObjValPtr *) gdgt->valueGrp->firstMember->obj; 235 236 switch (vp->datatype) { 237 case OBJ_VALUE_FLOAT: 238 get_objvalue(&gdgt->varval, OBJ_VALUE_FLOAT, vp->obj, vp->offset); 239 gdgt->sliderPos = (gdgt->varval.f - gdgt->rangeMin) * range; 240 break; 241 case OBJ_VALUE_INT: 242 get_objvalue(&gdgt->varval, OBJ_VALUE_INT, vp->obj, vp->offset); 243 gdgt->sliderPos = (gdgt->varval.i - gdgt->rangeMin) * range; 244 break; 245 default: 246 fatal_printf("%s: Undefined ValueType", "reset_gadget"); 247 } 248 } 249 } 250 251 /* 23A940 -> 23A980 */ 252 void reset_gadgets_in_grp(struct ObjGroup *grp) { 253 apply_to_obj_types_in_group(OBJ_TYPE_GADGETS, (applyproc_t) reset_gadget, grp); 254 }