From 9c3c1b9ac1f390a1c62f8ced6469057a58879477 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 24 Nov 2010 11:49:38 +0900 Subject: [PATCH] Use @param instead of id to pass objects within the menu parser. This allows mixed types (eg, objects and Rects). To be passed around. This sorts out the changes needed for the conversion of Rect from object to struct. --- ruamoko/cl_menu/Makefile.am | 2 +- ruamoko/cl_menu/options.qc | 69 ++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/ruamoko/cl_menu/Makefile.am b/ruamoko/cl_menu/Makefile.am index a51951a92..3dcbd5db5 100644 --- a/ruamoko/cl_menu/Makefile.am +++ b/ruamoko/cl_menu/Makefile.am @@ -28,7 +28,7 @@ EXTRA_DATA= $(menu_data) menu_src= \ client_menu.qc controls_o.qc options.qc options_util.qc servlist.qc \ - Frame.r menu.r HUD.r + Frame.r menu.r HUD.r ../lib/debug.r %.qfo: %.r $(QFCC) $(QCFLAGS) $(QCPPFLAGS) -c -o $@ $< diff --git a/ruamoko/cl_menu/options.qc b/ruamoko/cl_menu/options.qc index deca5b4e8..5b9d29dbf 100644 --- a/ruamoko/cl_menu/options.qc +++ b/ruamoko/cl_menu/options.qc @@ -24,6 +24,7 @@ Boston, MA 02111-1307, USA */ +#include "debug.h" #include "options.h" #include "cbuf.h" #include "menu.h" @@ -101,14 +102,13 @@ InputLine network_config_iactive; * Video settings menu code ****************************/ -void dprint (string str) = #0; +@param object_from_plist (PLItem plist); -id object_from_plist (PLItem plist); - -id +@param class_from_plist (PLDictionary pldict) { local @param [8]params; + local @param ret; local @va_list va_list = { 0, params }; local string classname, selname, paramstr; local Class class; @@ -122,7 +122,8 @@ class_from_plist (PLDictionary pldict) class = obj_lookup_class (classname); if (!class) { dprint ("could not find " + classname + "\n"); - return NIL; + ret.pointer_val = NIL; + return ret; } obj = [class alloc]; @@ -141,7 +142,7 @@ class_from_plist (PLDictionary pldict) break; case "$": item = [pldict getObjectForKey:str_mid (paramstr, 1)]; - va_list.list[j].pointer_val = object_from_plist (item); + va_list.list[j] = object_from_plist (item); break; case "0": case "1": case "2": case "3": case "4": case "5": case "6": case "7": case "8": case "9": @@ -154,58 +155,78 @@ class_from_plist (PLDictionary pldict) } obj_msg_sendv (obj, sel, va_list); } - return obj; + ret.pointer_val = obj; + return ret; } -id +@param array_from_plist (PLArray plarray) { local Array array; local integer i, count; + local @param ret; array = [[Array alloc] init]; count = [plarray count]; for (i = 0; i < count; i++) [array addItem: object_from_plist ([plarray getObjectAtIndex:i])]; - return array; + ret.pointer_val = array; + return ret; } -Rect +union ParamRect { + @param p; + Rect r; +}; + +@param rect_from_plist (PLString plstring) { local string str = [plstring string]; local string tmp; local integer xp, yp, xl, yl; local PLItem item; + local union ParamRect pr; + pr.r = makeRect (0, 0, 0, 0); if (str_mid (str, 0, 1) == "[") { tmp = "(" + str_mid (str, 1, -1) + ")"; - item = [PLItem newFromString:tmp]; + item = [PLItem fromString:tmp]; xp = stoi ([(PLString) [item getObjectAtIndex:0] string]); yp = stoi ([(PLString) [item getObjectAtIndex:1] string]); xl = stoi ([(PLString) [item getObjectAtIndex:2] string]); yl = stoi ([(PLString) [item getObjectAtIndex:3] string]); - return makeRect (xp, yp, xl, yl); + pr.r = makeRect (xp, yp, xl, yl); } - return makeRect (0, 0, 0, 0); + return pr.p; } -id +@param string_from_plist (PLString plstring) { - return NIL; + local @param ret; + local string str = [plstring string]; + + if (str_mid (str, 0, 1) == "[") + return rect_from_plist (plstring); + + ret.string_val = NIL; + return ret; } -id +@param object_from_plist (PLItem plist) { + local @param ret; + switch ([plist type]) { case QFDictionary: return class_from_plist ((PLDictionary) plist); case QFArray: return array_from_plist ((PLArray) plist); case QFBinary: - return NIL; + ret.pointer_val = NIL; + return ret; case QFString: return string_from_plist ((PLString) plist); } @@ -257,13 +278,16 @@ KEY_video_options = void () MENU_video_options = { + local @param ret; Menu_Begin (54, 50, "Video"); Menu_FadeScreen (1); Menu_Draw (DRAW_video_options); Menu_KeyEvent (KEY_video_options); - if (menu_plist) - video_options = object_from_plist ([menu_plist getObjectForKey:"video_options"]); + if (menu_plist) { + ret = object_from_plist ([menu_plist getObjectForKey:"video_options"]); + video_options = ret.pointer_val; + } Menu_End (); }; @@ -301,13 +325,16 @@ KEY_audio_options = void () MENU_audio_options = { + local @param ret; Menu_Begin (54, 60, "Audio"); Menu_FadeScreen (1); Menu_Draw (DRAW_audio_options); Menu_KeyEvent (KEY_audio_options); - if (menu_plist) - audio_options = object_from_plist ([menu_plist getObjectForKey:"audio_options"]); + if (menu_plist) { + ret = object_from_plist ([menu_plist getObjectForKey:"audio_options"]); + audio_options = ret.pointer_val; + } Menu_End (); };