std::unique_ptr<WorkRequest> invokeWithCallback(Fn&& fn, Cb&& callback, Args&&... args) { auto flag = std::make_shared<std::atomic<bool>>(); *flag = false; // Create a lambda L1 that invokes another lambda L2 on the current RunLoop R, that calls // the callback C. Both lambdas check the flag before proceeding. L1 needs to check the flag // because if the request was cancelled, then R might have been destroyed. L2 needs to check // the flag because the request may have been cancelled after L2 was invoked but before it // began executing. auto after = [flag, current = RunLoop::Get(), callback1 = std::move(callback)] (auto&&... results1) { if (!*flag) { current->invoke([flag, callback2 = std::move(callback1)] (auto&&... results2) { if (!*flag) { callback2(std::move(results2)...); } }, std::move(results1)...); } }; auto tuple = std::make_tuple(std::move(args)..., after); auto task = std::make_shared<Invoker<Fn, decltype(tuple)>>( std::move(fn), std::move(tuple), flag); push(task); return std::make_unique<WorkRequest>(task); }
void CLogSvcServer::RegisterServerSocketEventHandlers( void ) { TEventCallback callback( this, &CLogSvcServer::OnServerSocketClientConnected ); SubscribeTo( &m_tcpServer , COMCORE::CTCPServerSocket::ClientConnectedEvent , callback ); TEventCallback callback2( this, &CLogSvcServer::OnServerSocketClientDisconnected ); SubscribeTo( &m_tcpServer , COMCORE::CTCPServerSocket::ClientDisconnectedEvent , callback2 ); TEventCallback callback3( this, &CLogSvcServer::OnServerSocketClientError ); SubscribeTo( &m_tcpServer , COMCORE::CTCPServerSocket::ClientErrorEvent , callback3 ); TEventCallback callback4( this, &CLogSvcServer::OnServerSocketServerSocketClosed ); SubscribeTo( &m_tcpServer , COMCORE::CTCPServerSocket::ServerSocketClosedEvent , callback4 ); TEventCallback callback5( this, &CLogSvcServer::OnServerSocketServerSocketError ); SubscribeTo( &m_tcpServer , COMCORE::CTCPServerSocket::ServerSocketErrorEvent , callback5 ); TEventCallback callback6( this, &CLogSvcServer::OnServerSocketServerSocketClientError ); SubscribeTo( &m_tcpServer , COMCORE::CTCPServerSocket::ServerSocketClientErrorEvent , callback6 ); }
void do_call() { int i = callback(); printf("callback returned %d to c\n", i); int j = callback2(123, 8.76); printf("callback2 returned %d to c\n", j); double d = callback3(); printf("callback3 returned %f to c\n", d); }
void http_request_async(const http_request_t * request, void (*callback)(http_response_t*)) { auto request2 = HttpRequest2(request); auto thread = std::thread([](const HttpRequest2 &req, void(*callback2)(http_response_t*)) -> void { http_response_t * response = http_request(req); callback2(response); }, std::move(request2), callback); thread.detach(); }
void MyServiceAsyncClient::sync_getDataById(apache::thrift::RpcOptions& rpcOptions, std::string& _return, int64_t id) { apache::thrift::ClientReceiveState _returnState; std::unique_ptr<apache::thrift::RequestCallback> callback2(new apache::thrift::ClientSyncCallback(&_returnState, getChannel()->getEventBase(), false)); getDataById(rpcOptions, std::move(callback2), id); getChannel()->getEventBase()->loopForever(); if (!_returnState.buf()) { assert(_returnState.exception()); std::rethrow_exception(_returnState.exception()); } recv_getDataById(_return, _returnState); }
static void camluv_check_cb(uv_check_t* uv_handle, int status) { camluv_enter_callback(); CAMLlocal3(check_cb, camluv_handle, camluv_status); camluv_check_t *camluv_check =(camluv_check_t *)(uv_handle->data); check_cb = camluv_check->check_cb; camluv_handle = camluv_copy_check(camluv_check); camluv_status = Val_int(status); callback2(check_cb, camluv_handle, camluv_status); camluv_leave_callback(); }
void gsl_multimin_callback_df(const gsl_vector *x, void *params, gsl_vector *G) { int barr_flags = BIGARRAY_FLOAT64 | BIGARRAY_C_LAYOUT; struct callback_params *p=params; value x_barr, g_barr; int len = x->size; gsl_vector_view x_v, g_v; x_barr = alloc_bigarray_dims(barr_flags, 1, NULL, len); g_barr = alloc_bigarray_dims(barr_flags, 1, NULL, len); x_v = gsl_vector_view_array(Data_bigarray_val(x_barr), len); g_v = gsl_vector_view_array(Data_bigarray_val(g_barr), len); gsl_vector_memcpy(&x_v.vector, x); callback2(Field(p->closure, 1), x_barr, g_barr); gsl_vector_memcpy(G, &g_v.vector); }
bool ClientHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message) { if (message->GetName().ToString() == "show_keyboard"){ PostCallback(callback1(WhenKeyboard, true)); }else if (message->GetName().ToString() == "hide_keyboard"){ PostCallback(callback1(WhenKeyboard, false)); }else{ CefRefPtr<CefListValue> args = message->GetArgumentList(); Upp::Vector<Upp::Value> par; for (unsigned i = 0; i < args->GetSize(); i++){ CefValueType type = args->GetType(i); switch(type){ case VTYPE_BOOL: par.Add(args->GetBool(i)); break; case VTYPE_DOUBLE: par.Add(args->GetDouble(i)); break; case VTYPE_INT: par.Add(args->GetInt(i)); break; case VTYPE_STRING: par.Add(args->GetString(i).ToString().c_str()); break; default: par.Add("OnProcessMessageReceived: unsupported parameter type"); break; } } PostCallback(callback2(WhenMessage, message->GetName().ToString(), par)); } return true; }
/* MULTIROOT CALLBACKS */ int gsl_multiroot_callback(const gsl_vector *x, void *params, gsl_vector *F) { int barr_flags = BIGARRAY_FLOAT64 | BIGARRAY_C_LAYOUT; struct callback_params *p=params; value x_barr, f_barr; int len = x->size; gsl_vector_view x_v, f_v; x_barr = alloc_bigarray_dims(barr_flags, 1, NULL, len); f_barr = alloc_bigarray_dims(barr_flags, 1, NULL, len); x_v = gsl_vector_view_array(Data_bigarray_val(x_barr), len); f_v = gsl_vector_view_array(Data_bigarray_val(f_barr), len); gsl_vector_memcpy(&x_v.vector, x); callback2(p->closure, x_barr, f_barr); gsl_vector_memcpy(F, &f_v.vector); return GSL_SUCCESS; }
int gsl_multiroot_callback_df(const gsl_vector *x, void *params, gsl_matrix *J) { int barr_flags = BIGARRAY_FLOAT64 | BIGARRAY_C_LAYOUT; struct callback_params *p=params; value x_barr, j_barr; int len = x->size; gsl_vector_view x_v; gsl_matrix_view j_v; x_barr = alloc_bigarray_dims(barr_flags, 1, NULL, len); j_barr = alloc_bigarray_dims(barr_flags, 2, NULL, len, len); x_v = gsl_vector_view_array(Data_bigarray_val(x_barr), len); j_v = gsl_matrix_view_array(Data_bigarray_val(j_barr), len, len); gsl_vector_memcpy(&x_v.vector, x); callback2(Field(p->closure, 1), x_barr, j_barr); gsl_matrix_memcpy(J, &j_v.matrix); return GSL_SUCCESS; }
/* MULTIFIT CALLBACKS */ int gsl_multifit_callback_f(const gsl_vector *X, void *params, gsl_vector *F) { int barr_flags = BIGARRAY_FLOAT64 | BIGARRAY_C_LAYOUT; struct callback_params *parms=params; value x_barr, f_barr; size_t p = X->size; size_t n = F->size; gsl_vector_view x_v, f_v; x_barr = alloc_bigarray_dims(barr_flags, 1, NULL, p); f_barr = alloc_bigarray_dims(barr_flags, 1, NULL, n); x_v = gsl_vector_view_array(Data_bigarray_val(x_barr), p); f_v = gsl_vector_view_array(Data_bigarray_val(f_barr), n); gsl_vector_memcpy(&x_v.vector, X); callback2(Field(parms->closure, 0), x_barr, f_barr); gsl_vector_memcpy(F, &f_v.vector); return GSL_SUCCESS; }
void main() { WItemsNum = __VERIFIER_nondet_int(); while(1) { while(WItemsNum<=5 || MoreWItems()) { if (WItemsNum<=5) { callback1(); WItemsNum++; } else { WItemsNum++; } } while(WItemsNum>2) { callback2(); WItemsNum--; } } while(1) {} }
inline void body() { WItemsNum = nondet(); while(1) { while(WItemsNum<=5 || MoreWItems()) { if (WItemsNum<=5) { callback1(); WItemsNum++; } else { WItemsNum++; } } while(WItemsNum>2) { callback2(); WItemsNum--; } } while(1) {} }
/* The Tcl command for evaluating callback in OCaml */ int CamlCBCmd(ClientData clientdata, Tcl_Interp *interp, int argc, CONST84 char **argv) { CheckInit(); /* Assumes no result */ Tcl_SetResult(interp, NULL, NULL); if (argc >= 2) { int id; if (Tcl_GetInt(interp, argv[1], &id) != TCL_OK) return TCL_ERROR; callback2(*handler_code,Val_int(id), copy_string_list(argc - 2,(char **)&argv[2])); /* Never fails (OCaml would have raised an exception) */ /* but result may have been set by callback */ return TCL_OK; } else return TCL_ERROR; }
static void *sound_rpc_server(int funcno, void *data, int size) { uint32_t *param = data; funcno = funcno; size = size; if (param[0] & 0x01) { /* DMA 0 */ if(callback1 != NULL) { return (void *) callback1(callback1_arg, 0); } } if (param[0] & 0x02) { /* DMA 1 */ if(callback2 != NULL) { return (void *) callback2(callback2_arg, 1); } } return NULL; }
int eqconrep (char *trep1, int trep1len, char *trep2, int trep2len) { CAMLparam0(); CAMLlocal3(Caml_trep1, Caml_trep2, answer); static value *cast_closure = NULL; static int retval = 0; Caml_trep1 = alloc_string(trep1len); Caml_trep2 = alloc_string(trep2len); memcpy (String_val(Caml_trep1), trep1, trep1len); memcpy (String_val(Caml_trep2), trep2, trep2len); if (cast_closure == NULL) cast_closure = caml_named_value ("eqconrep"); answer = callback2(*cast_closure, Caml_trep1, Caml_trep2); if (answer == Val_int(1)) retval = 1; else retval = 0; CAMLreturn(retval); }
String GatherTpp::GatherTopics(const char *topic, String& title) { static StaticCriticalSection mapl; int q; INTERLOCKED_(mapl) q = tt.Find(topic); if(q < 0) { Topic p = ReadTopic(LoadFile(TopicFileName(topic))); title = p.title; String t = p; if(IsNull(t)) { String topicEng = ChangeTopicLanguage(topic, LNG_('E','N','U','S')); p = ReadTopic(LoadFile(TopicFileName(topicEng))); String tt = p; if(IsNull(tt)) return "index.html"; title = p.title; p.title += " (translated)"; String help = "topic://uppweb/www/contribweb$" + GetTopicLanguage(topic); p.text = String("{{1f1t0/50b0/50@(240.240.240) [<A2 ") + t_("This page has not been translated yet") + "]. " + "[^" + help + "^ [<A2 " + t_("Do you want to translate it?") + "]]}}&&" + p.text; } INTERLOCKED_(mapl) tt.Add(topic) = p; GatherLinkIterator ti(&reflink); ParseQTF(t).Iterate(ti); #ifdef MTC CoWork work; for(int i = 0; i < ti.link.GetCount(); i++) work & callback2(sGatherTopics, &tt, ti.link[i]); #else for(int i = 0; i < ti.link.GetCount(); i++) GatherTopics(ti.link[i]); #endif } else { INTERLOCKED_(mapl) title = tt[q].title; } return TopicFileNameHtml(topic); }
void CHighlightableButton::select(bool on) { selected = on; if (on) { borderEnabled = true; setState(HIGHLIGHTED); callback(); } else { borderEnabled = false; setState(NORMAL); callback2(); } if(hoverTexts.size()>1) { hover(false); hover(true); } }
void runTest () { beginTestCase ("create"); Factory <Object> factory; Callback1 callback1 (factory); Callback2 callback2 (factory); Object object (*this); factory.create_interfaces (object); // find existing interfaces expect (object.find_interface <Interface1> () != nullptr); expect (object.find_interface <Interface2> () != nullptr); // add duplicate interface try { object.add_interface (new Interface1); fail ("uncaught exeption"); } catch (std::invalid_argument const&) { pass (); } // request missing interface try { struct MissingInterface { }; object.get_interface <MissingInterface> (); fail ("uncaught exeption"); } catch (std::bad_cast const&) { pass (); } }
int gsl_multifit_callback_df(const gsl_vector *X, void *params, gsl_matrix *J) { int barr_flags = BIGARRAY_FLOAT64 | BIGARRAY_C_LAYOUT; struct callback_params *parms=params; value x_barr, j_barr; size_t p = X->size; size_t n = J->size1; gsl_vector_view x_v; gsl_matrix_view j_v; value res; x_barr = alloc_bigarray_dims(barr_flags, 1, NULL, p); j_barr = alloc_bigarray_dims(barr_flags, 2, NULL, n, p); x_v = gsl_vector_view_array(Data_bigarray_val(x_barr), p); j_v = gsl_matrix_view_array(Data_bigarray_val(j_barr), n, p); gsl_vector_memcpy(&x_v.vector, X); res=callback2(Field(parms->closure, 1), x_barr, j_barr); if(Is_exception_result(res)) return GSL_FAILURE; gsl_matrix_memcpy(J, &j_v.matrix); return GSL_SUCCESS; }
void body() { __rho_1_ = nondet(); WItemsNum = __rho_1_; while(1) { while(1) { __rho_2_ = MoreWItems(); if (WItemsNum<=5) { if (__rho_2_>0) break; } if (WItemsNum<=5) { callback1(); WItemsNum++; } else { WItemsNum++; } } while(1) { if (!(WItemsNum>2)) break; callback2(); WItemsNum--; } } while(1) { dummy=dummy; } L_return: return 0; }
void Ide::SetupFormat() { FormatDlg dlg; dlg.Title("Format setup"); WithSetupFontLayout<ParentCtrl> fnt; WithSetupHlLayout<ParentCtrl> hlt; WithSetupEditorLayout<ParentCtrl> edt; WithSetupIdeLayout<ParentCtrl> ide; WithSetupAssistLayout<ParentCtrl> assist; WithSetupMobilePlatformsLayout<ParentCtrl> mobile; AStyleSetupDialog ast(this); #ifdef PLATFORM_WIN32 ide.console_txt.Hide(); ide.console.Hide(); ide.kde.Hide(); ide.gnome.Hide(); ide.xterm.Hide(); ide.mate.Hide(); #endif ide.kde <<= callback2(SetConsole, &ide.console, "/usr/bin/konsole -e"); ide.gnome <<= callback2(SetConsole, &ide.console, "/usr/bin/gnome-terminal -x"); ide.mate <<= callback2(SetConsole, &ide.console, "/usr/bin/mate-terminal -x"); ide.xterm <<= callback2(SetConsole, &ide.console, "/usr/bin/xterm -e"); edt.lineends .Add(LF, "LF") .Add(CRLF, "CRLF") .Add(DETECT_LF, "Detect with default LF") .Add(DETECT_CRLF, "Detect with default CRLF"); edt.filetabs .Add(AlignedFrame::LEFT, "Left") .Add(AlignedFrame::TOP, "Top") .Add(AlignedFrame::RIGHT, "Right") .Add(AlignedFrame::BOTTOM, "Bottom") .Add(-1, "Off"); edt.tabs_crosses .Add(AlignedFrame::LEFT, "Left") .Add(AlignedFrame::RIGHT, "Right") .Add(-1, "Off"); dlg.Add(fnt, "Fonts"); dlg.Add(hlt, "Syntax highlighting"); dlg.Add(edt, "Editor"); dlg.Add(assist, "Assist"); dlg.Add(ide, "IDE"); dlg.Add(ast, "Code formatting"); dlg.Add(mobile, "Mobile platforms"); dlg.WhenClose = dlg.Acceptor(IDEXIT); FontSelectManager ed, vf, con, f1, f2, tf; ed.Set(fnt.face, fnt.height, fnt.bold, fnt.italic, fnt.naa); vf.Set(fnt.vface, fnt.vheight, fnt.vbold, fnt.vitalic, fnt.vnaa); con.Set(fnt.cface, fnt.cheight, fnt.cbold, fnt.citalic, fnt.cnaa); tf.Set(fnt.tface, fnt.theight, fnt.tbold, fnt.titalic, fnt.tnaa); f1.Set(fnt.face1, fnt.height1, fnt.bold1, fnt.italic1, fnt.naa1); f2.Set(fnt.face2, fnt.height2, fnt.bold2, fnt.italic2, fnt.naa2); ed.Set(editorfont); vf.Set(veditorfont); con.Set(consolefont); tf.Set(tfont); f1.Set(font1); f2.Set(font2); DlCharset(edt.charset); edt.tabsize.MinMax(1, 100).NotNull(); edt.tabsize <<= editortabsize; edt.indent_amount.MinMax(1, 100).NotNull(); edt.indent_amount <<= indent_spaces ? indent_amount : editortabsize; edt.indent_amount.Enable(indent_spaces); CtrlRetriever rtvr; int hs = hilite_scope; rtvr (hlt.hilite_scope, hs) (hlt.hilite_bracket, hilite_bracket) (hlt.hilite_ifdef, hilite_ifdef) (hlt.hilite_if_endif, hilite_if_endif) (hlt.thousands_separator, thousands_separator) (hlt.hline, hline) (edt.indent_spaces, indent_spaces) (edt.no_parenthesis_indent, no_parenthesis_indent) (edt.showtabs, show_tabs) (edt.warnwhitespace, warnwhitespace) (edt.lineends, line_endings) (edt.numbers, line_numbers) (edt.bookmark_pos, bookmark_pos) (edt.bordercolumn, bordercolumn) (edt.bordercolor, bordercolor) (edt.findpicksel, find_pick_sel) (edt.findpicktext, find_pick_text) (edt.deactivate_save, deactivate_save) (edt.filetabs, filetabs) (edt.tabs_icons, tabs_icons) (edt.tabs_crosses, tabs_crosses) (edt.tabs_grouping, tabs_grouping) (edt.tabs_stacking, tabs_stacking) (edt.tabs_serialize, tabs_serialize) (edt.persistent_find_replace, persistent_find_replace) (edt.find_replace_restore_pos, find_replace_restore_pos) (assist.barline, barline) (assist.auto_enclose, auto_enclose) (assist.commentdp, editor.commentdp) (assist.header_guards, header_guards) (assist.insert_include, insert_include) (assist.mark_lines, mark_lines) (assist.qtfsel, qtfsel) (assist.assist, editor.auto_assist) (ide.showtime, showtime) (ide.show_status_bar, show_status_bar) (ide.toolbar_in_row, toolbar_in_row) (ide.splash_screen, splash_screen) (ide.sort, sort) (ide.mute_sounds, mute_sounds) (ide.wrap_console_text, wrap_console_text) (ide.hydra1_threads, hydra1_threads) (ide.gdbSelector, gdbSelector) (ide.chstyle, chstyle) (ide.console, LinuxHostConsole) (ide.output_per_assembly, output_per_assembly) (ast.BracketIndent, astyle_BracketIndent) (ast.NamespaceIndent, astyle_NamespaceIndent) (ast.BlockIndent, astyle_BlockIndent) (ast.CaseIndent, astyle_CaseIndent) (ast.ClassIndent, astyle_ClassIndent) (ast.LabelIndent, astyle_LabelIndent) (ast.SwitchIndent, astyle_SwitchIndent) (ast.PreprocessorIndent, astyle_PreprocessorIndent) (ast.MinInStatementIndentLength, astyle_MinInStatementIndentLength) (ast.MaxInStatementIndentLength, astyle_MaxInStatementIndentLength) (ast.BreakClosingHeaderBracketsMode,astyle_BreakClosingHeaderBracketsMode) (ast.BreakElseIfsMode, astyle_BreakElseIfsMode) (ast.BreakOneLineBlocksMode, astyle_BreakOneLineBlocksMode) (ast.SingleStatementsMode, astyle_SingleStatementsMode) (ast.BreakBlocksMode, astyle_BreakBlocksMode) (ast.BreakClosingHeaderBlocksMode, astyle_BreakClosingHeaderBlocksMode) (ast.BracketFormatMode, astyle_BracketFormatMode) (ast.ParensPaddingMode, astyle_ParensPaddingMode) (ast.ParensUnPaddingMode, astyle_ParensUnPaddingMode) (ast.OperatorPaddingMode, astyle_OperatorPaddingMode) (ast.EmptyLineFill, astyle_EmptyLineFill) (ast.TabSpaceConversionMode, astyle_TabSpaceConversionMode) (ast.TestBox, astyle_TestBox) (mobile.AndroidSDKPath, androidSDKPath) ; hlt.hlstyle.AddColumn("Style"); hlt.hlstyle.AddColumn("Color").Ctrls(HlPusherFactory); hlt.hlstyle.AddColumn("Bold").Ctrls<Option>(); hlt.hlstyle.AddColumn("Italic").Ctrls<Option>(); hlt.hlstyle.AddColumn("Underline").Ctrls<Option>(); hlt.hlstyle.ColumnWidths("211 80 45 45 80"); hlt.hlstyle.EvenRowColor().NoHorzGrid().SetLineCy(EditField::GetStdHeight() + 2); ReadHlStyles(hlt.hlstyle); edt.charset <<= (int)default_charset; edt.tabsize <<= rtvr <<= hlt.hlstyle.WhenCtrlsAction = ed.WhenAction = tf.WhenAction = con.WhenAction = f1.WhenAction = f2.WhenAction = dlg.Breaker(222); ide.showtimeafter <<= Nvl((Date)FileGetTime(ConfigFile("version")), GetSysDate() - 1); hlt.hl_restore <<= dlg.Breaker(333); ide.chstyle.Add(0, "Host platform"); ide.chstyle.Add(1, "Standard"); ide.chstyle.Add(2, "Classic"); ide.chstyle.Add(3, "Host platform, blue bars"); ide.chstyle.Add(4, "Standard, blue bars"); FrameRight<Button> uscBrowse; uscBrowse.SetImage(CtrlImg::right_arrow()); uscBrowse <<= callback1(AddPath, &ide.uscpath); ide.uscpath.AddFrame(uscBrowse); ide.uscpath <<= LoadFile(GetHomeDirFile("usc.path")); FrameRight<Button> androidSDKDownload; androidSDKDownload.SetImage(IdeImg::DownloadBlack()); androidSDKDownload.Tip("Download"); androidSDKDownload <<= callback1(LaunchWebBrowser, AndroidSDK::GetDownloadUrl()); mobile.AndroidSDKPath.AddFrame(androidSDKDownload); FrameRight<Button> androidSDKBrowse; androidSDKBrowse.SetImage(CtrlImg::right_arrow()); androidSDKBrowse.Tip("Select directory"); androidSDKBrowse <<= callback1(InsertPath, &mobile.AndroidSDKPath); mobile.AndroidSDKPath.AddFrame(androidSDKBrowse); mobile.AndroidSDKPath <<= androidSDKPath; for(;;) { int c = dlg.Run(); Upp::SaveFile(GetHomeDirFile("usc.path"), ~ide.uscpath); editorfont = ed.Get(); tfont = tf.Get(); veditorfont = vf.Get(); consolefont = con.Get(); font1 = f1.Get(); font2 = f2.Get(); editortabsize = Nvl((int)~edt.tabsize, 4); rtvr.Retrieve(); console.SetSlots(minmax(hydra1_threads, 1, 256)); hilite_scope = hs; if(indent_spaces) indent_amount = ~edt.indent_amount; else { indent_amount = editortabsize; edt.indent_amount <<= editortabsize; } edt.indent_amount.Enable(indent_spaces); default_charset = (byte)(int)~edt.charset; for(int i = 0; i < CodeEditor::HL_COUNT; i++) editor.SetHlStyle(i, hlt.hlstyle.Get(i, 1), hlt.hlstyle.Get(i, 2), hlt.hlstyle.Get(i, 3), hlt.hlstyle.Get(i, 4)); UpdateFormat(); if(c == IDEXIT) break; if(c == 333 && PromptYesNo("Restore default highlighting colors?")) { editor.DefaultHlStyles(); ReadHlStyles(hlt.hlstyle); } } FileSetTime(ConfigFile("version"), ToTime(~ide.showtimeafter)); FinishConfig(); SaveConfig(); }
int Prompt(Callback1<const String&> WhenLink, const char *title, const Image& iconbmp, const char *qtf, bool okcancel, const char *button1, const char *button2, const char *button3, int cx, Image im1, Image im2, Image im3) { int fcy = Draw::GetStdFontCy(); PromptDlgWnd__ dlg; RichTextCtrl qtfctrl; Icon icon; qtfctrl.WhenLink = WhenLink; icon.SetImage(iconbmp); Button b1, b2, b3; qtfctrl.SetQTF(String("[G1 ") + qtf, GetRichTextStdScreenZoom()); int bcy = Ctrl::VertLayoutZoom(24); int bcx = Ctrl::HorzLayoutZoom(72); if(button1) bcx = max(2 * fcy + GetTextSize(button1, Draw::GetStdFont()).cx, bcx); if(button2) bcx = max(2 * fcy + GetTextSize(button2, Draw::GetStdFont()).cx, bcx); if(button3) bcx = max(2 * fcy + GetTextSize(button3, Draw::GetStdFont()).cx, bcx); Size bsz = icon.GetStdSize(); if(cx == 0) { cx = qtfctrl.GetWidth(); if(!cx) cx = 350; cx += 2 * fcy; if(bsz.cx) cx += bsz.cx + fcy; } int nbtn = !!button1 + !!button2 + !!button3; dlg.esc = okcancel && nbtn == 1; cx = min(550, max(nbtn * bcx + (1 + nbtn) * fcy, cx)); int qcx = cx - 2 * fcy; if(bsz.cx) qcx -= bsz.cx + fcy; int ccy = qtfctrl.GetHeight(qcx); int qcy = min(400, ccy); if(qcy <= ccy) { qcx += ScrollBarSize() + fcy; cx += ScrollBarSize() + fcy; } int mcy = max(qcy, bsz.cy); int cy = mcy + 48 * fcy / 10; dlg.SetRect(Size(cx, cy)); dlg << icon.TopPos(fcy, bsz.cy).LeftPos(fcy, bsz.cx); dlg << qtfctrl.TopPos(fcy + (mcy - qcy) / 2, qcy).RightPos(fcy, qcx); if(okcancel) { b1.Ok(); if(nbtn == 2) b2.Cancel(); if(nbtn == 3) b3.Cancel(); } b1.WhenAction = dlg.Breaker(1); b2.WhenAction = dlg.Breaker(0); b3.WhenAction = dlg.Breaker(-1); dlg.b = &b1; int bx = bcx; int gap = fcy / 2; fcy = 8 * fcy / 10; if(button2) bx += gap + bcx; if(button3) bx += gap + bcx; bx = (cx - bx) / 2; if(SwapOKCancel()) { sAdd(dlg, fcy, bcy, bx, bcx, gap, b2, button2, im2); sAdd(dlg, fcy, bcy, bx, bcx, gap, b3, button3, im3); sAdd(dlg, fcy, bcy, bx, bcx, gap, b1, button1, im1); } else { sAdd(dlg, fcy, bcy, bx, bcx, gap, b1, button1, im1); sAdd(dlg, fcy, bcy, bx, bcx, gap, b2, button2, im2); sAdd(dlg, fcy, bcy, bx, bcx, gap, b3, button3, im3); } dlg.WhenClose = dlg.Breaker(button3 ? -1 : 0); dlg.Title(title); int result; Ctrl::Call(callback2(sExecutePrompt, &dlg, &result)); return result; }
/* Basically the same thing as FileProc */ void TimerProc (ClientData clientdata) { callback2(*handler_code,Val_long(clientdata),Val_int(0)); }
void btKinematicCharacterController::stepDown ( btCollisionWorld* collisionWorld, btScalar dt) { btTransform start, end, end_double; bool runonce = false; // phase 3: down /*btScalar additionalDownStep = (m_wasOnGround && !onGround()) ? m_stepHeight : 0.0; btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + additionalDownStep); btScalar downVelocity = (additionalDownStep == 0.0 && m_verticalVelocity<0.0?-m_verticalVelocity:0.0) * dt; btVector3 gravity_drop = getUpAxisDirections()[m_upAxis] * downVelocity; m_targetPosition -= (step_drop + gravity_drop);*/ btVector3 orig_position = m_targetPosition; btScalar downVelocity = (m_verticalVelocity<0.f?-m_verticalVelocity:0.f) * dt; if(downVelocity > 0.0 && downVelocity > m_fallSpeed && (m_wasOnGround || !m_wasJumping)) downVelocity = m_fallSpeed; btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + downVelocity); m_targetPosition -= step_drop; btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, getUpAxisDirections()[m_upAxis], m_maxSlopeCosine); callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup; callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask; btKinematicClosestNotMeConvexResultCallback callback2 (m_ghostObject, getUpAxisDirections()[m_upAxis], m_maxSlopeCosine); callback2.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup; callback2.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask; while (1) { start.setIdentity (); end.setIdentity (); end_double.setIdentity (); start.setOrigin (m_currentPosition); end.setOrigin (m_targetPosition); //set double test for 2x the step drop, to check for a large drop vs small drop end_double.setOrigin (m_targetPosition - step_drop); if (m_useGhostObjectSweepTest) { m_ghostObject->convexSweepTest (m_convexShape, start, end, callback, collisionWorld->getDispatchInfo().m_allowedCcdPenetration); if (!callback.hasHit()) { //test a double fall height, to see if the character should interpolate it's fall (full) or not (partial) m_ghostObject->convexSweepTest (m_convexShape, start, end_double, callback2, collisionWorld->getDispatchInfo().m_allowedCcdPenetration); } } else { collisionWorld->convexSweepTest (m_convexShape, start, end, callback, collisionWorld->getDispatchInfo().m_allowedCcdPenetration); if (!callback.hasHit()) { //test a double fall height, to see if the character should interpolate it's fall (large) or not (small) collisionWorld->convexSweepTest (m_convexShape, start, end_double, callback2, collisionWorld->getDispatchInfo().m_allowedCcdPenetration); } } btScalar downVelocity2 = (m_verticalVelocity<0.f?-m_verticalVelocity:0.f) * dt; bool has_hit = false; if (bounce_fix == true) has_hit = callback.hasHit() || callback2.hasHit(); else has_hit = callback2.hasHit(); if(downVelocity2 > 0.0 && downVelocity2 < m_stepHeight && has_hit == true && runonce == false && (m_wasOnGround || !m_wasJumping)) { //redo the velocity calculation when falling a small amount, for fast stairs motion //for larger falls, use the smoother/slower interpolated movement by not touching the target position m_targetPosition = orig_position; downVelocity = m_stepHeight; btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + downVelocity); m_targetPosition -= step_drop; runonce = true; continue; //re-run previous tests } break; } if (callback.hasHit() || runonce == true) { // we dropped a fraction of the height -> hit floor btScalar fraction = (m_currentPosition.getY() - callback.m_hitPointWorld.getY()) / 2; //printf("hitpoint: %g - pos %g\n", callback.m_hitPointWorld.getY(), m_currentPosition.getY()); if (bounce_fix == true) { if (full_drop == true) m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction); else //due to errors in the closestHitFraction variable when used with large polygons, calculate the hit fraction manually m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, fraction); } else m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction); full_drop = false; m_verticalVelocity = 0.0; m_verticalOffset = 0.0; m_wasJumping = false; } else { // we dropped the full height full_drop = true; if (bounce_fix == true) { downVelocity = (m_verticalVelocity<0.f?-m_verticalVelocity:0.f) * dt; if (downVelocity > m_fallSpeed && (m_wasOnGround || !m_wasJumping)) { m_targetPosition += step_drop; //undo previous target change downVelocity = m_fallSpeed; step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + downVelocity); m_targetPosition -= step_drop; } } //printf("full drop - %g, %g\n", m_currentPosition.getY(), m_targetPosition.getY()); m_currentPosition = m_targetPosition; } }
value reify_bytecode(value prog, value len) { return callback2(reify,prog,len); }
void FileProc(ClientData clientdata, int mask) { callback2(*handler_code,Val_int(clientdata),Val_int(0)); }
value mycallback2(value fun, value arg1, value arg2) { value res; res = callback2(fun, arg1, arg2); return res; }