void TracerManager::registerTracer(const string &tracerName, const string &tracerUnit, const MeshManager &meshManager) { NOTICE("TracerManager", "Register tracer \""+tracerName+"\""); tracerNames.push_back(tracerName); tracerUnits.push_back(tracerUnit); // ------------------------------------------------------------------------- // initialize tracer density on the mesh tracerDensities.push_back(Field()); if (meshManager.hasLayers()) tracerDensities.back().init(meshManager.getMesh(PointCounter::Center), meshManager.getMesh(PointCounter::Bound), meshManager.getLayers(Layers::Full)); else tracerDensities.back().init(meshManager.getMesh(PointCounter::Center), meshManager.getMesh(PointCounter::Bound)); // ------------------------------------------------------------------------- // set up tracer variables in polygons Polygon *polygon = polygonManager.polygons.front(); for (int i = 0; i < polygonManager.polygons.size(); ++i) { polygon->tracers.push_back(Tracer()); polygon = polygon->next; } }
// // Create_SubtopicLV // // This function creates a listview control within the topic window. The // listview will contain all the subtopics. This function returns the // handle of the list view control. // static HWND Create_SubtopicLV(HINSTANCE Instance, HWND Topic_Window) { RECT Topic_Rect; HWND List_Window; LV_COLUMN Col; GetClientRect(Topic_Window, &Topic_Rect); List_Window = CreateWindowEx( 0, WC_LISTVIEW, "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | LVS_REPORT, 0, Topic_Rect.bottom/2, Topic_Rect.right, Topic_Rect.bottom/2, Topic_Window, reinterpret_cast<HMENU>(1), Instance, 0 ); if (List_Window == 0) throw spica::Win32::API_Error("Can't create the subtopic listview"); Col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; Col.fmt = LVCFMT_LEFT; Col.cx = Topic_Rect.right; Col.pszText = "Subtopics"; Col.iSubItem = 0; int Err; Err = ListView_InsertColumn(List_Window, 0, &Col); if (Err == -1) throw spica::Win32::API_Error("Can't insert 'Topic' column into the subtopic listview"); Tracer(3, "Finished creating the subtopic listview."); return List_Window; }
static void_t * pvWatch( void_t *a_pvParam ) { int_t iRv = - 1; long_t liId = *(static_cast<long *>( a_pvParam )); xUNUSED(liId); #if 0 Tracer() << "Starting pvWatch(): thread " << liId; #endif /* Lock mutex and wait for signal. Note that the pthread_cond_wait routine will automatically and atomically unlock mutex while it waits. Also, note that if COUNT_LIMIT is reached before this routine is run by the waiting thread, the loop will be skipped to prevent pthread_cond_wait from never returning. */ iRv = ::pthread_mutex_lock(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); { while (g_uiCounter < g_cuiCounterMax) { iRv = ::pthread_cond_wait(&g_cndCondition, &g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); #if 0 Tracer() << xT("pvCountWatch(): thread: ") << liId << xT(" Condition signal received"); #endif g_uiCounter += 125; #if 0 Tracer() << xT("pvCountWatch(): thread: ") << liId << xT(" g_uiCounter: ") << g_uiCounter; #endif } } iRv = ::pthread_mutex_unlock(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); return xPTR_NULL; }
KOKKOS_INLINE_FUNCTION void XZHydrostatic_UTracer<EvalT, Traits>:: operator() (const XZHydrostatic_UTracer_Tag& tag, const int& cell) const{ for (int node=0; node < numNodes; ++node) for (int level=0; level < numLevels; ++level) for (int dim=0; dim < numDims; ++dim) UTracer(cell,node,level,dim) = Velocity(cell,node,level,dim)*Tracer(cell,node,level); }
static void_t * pvJob( void_t *a_pvParam ) { int_t iRv = - 1; long_t liId = *(static_cast<long *>( a_pvParam )); xUNUSED(liId); for (size_t i = 0; i < 10 /* g_cuiJobLoops */; ++ i) { iRv = ::pthread_mutex_lock(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); { ++ g_uiCounter; // Check the value of count and signal waiting thread when condition is reached if (g_uiCounter == g_cuiCounterMax) { iRv = ::pthread_cond_signal(&g_cndCondition); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); #if 0 Tracer() << xT("pvJob(): thread: ") << liId << xT(" g_uiCounter: ") << g_uiCounter << xT(" threshold reached"); #endif } #if 0 Tracer() << xT("pvJob(): thread: ") << liId << xT(" g_uiCounter: ") << g_uiCounter << xT(" unlocking mutex"); #endif } iRv = ::pthread_mutex_unlock(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); // do some "work" so threads can alternate on mutex lock { uint_t uiRv = ::sleep(1); xUNUSED(uiRv); } } return xPTR_NULL; }
int main(){ Tracer m("main"); { Tracer inner("inner"); foo(std::move(inner)); auto trace=bar(inner); trace.show(); inner.show(); } foo(Tracer("temp")); m.show(); }
void NPCMgr::Add_NewGame(int i_RoomID) { //SYSTEMTIME sys_now; //GetLocalTime(&sys_now); long curTime=GetTickCount(); pair<long,long> Tracer(curTime/1000,11); GlobalVar::TimeTracer[i_RoomID]=Tracer; init_playing_group(i_RoomID); GameBeginTime(i_RoomID); Actor_Info(i_RoomID); init_OrderList(i_RoomID); }
void ContourTracing(int cy, int cx, int labelindex, int tracingdirection, char *option) { char tracingstopflag = 0, SearchAgain = 1; int fx, fy, sx = cx, sy = cy; Tracer(&cy, &cx, &tracingdirection); if(option == "1") contourmap[cy][cx] = labelindex; if(cx != sx || cy != sy) { fx = cx; fy = cy; while(SearchAgain) { tracingdirection = (tracingdirection + 6) % 8; labelmap[cy][cx] = labelindex; Tracer(&cy, &cx, &tracingdirection); if(option == "1") contourmap[cy][cx] = labelindex; if(cx == sx && cy == sy) { tracingstopflag = 1; } else if(tracingstopflag) { if(cx == fx && cy == fy) { SearchAgain = 0; } else { tracingstopflag = 0; } } } } }
void XZHydrostatic_UTracer<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { for (int cell=0; cell < workset.numCells; ++cell) for (int node=0; node < numNodes; ++node) for (int level=0; level < numLevels; ++level) for (int dim=0; dim < numDims; ++dim) { UTracer(cell,node,level,dim) = Velx(cell,node,level,dim)*Tracer(cell,node,level); //UTracer(cell,node,level,dim) = PiVelx(cell,node,level,dim)*Tracer(cell,node,level); //std::cout << "pivelx: " << cell << " " << node << " " << level << " " << dim << " " << PiVelx(cell,node,level,dim) << std::endl; //std::cout << "Tracer " << Tracer(cell,node,level) << std::endl; } }
// // Set_Classes // // This function defines the various window classes the program needs. // static void Set_Classes() { WNDCLASS The_Class; // Define an appropriate window class for the main window. The_Class.style = CS_HREDRAW | CS_VREDRAW; The_Class.lpfnWndProc = Frame_Procedure; The_Class.cbClsExtra = 0; The_Class.cbWndExtra = 0; The_Class.hInstance = Global::Get_Instance(); The_Class.hIcon = LoadIcon(Global::Get_Instance(), MAKEINTRESOURCE(MAIN_ICON)); The_Class.hCursor = LoadCursor(0, IDC_ARROW); The_Class.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_APPWORKSPACE + 1); The_Class.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU); The_Class.lpszClassName = Frame_ClassName; if (RegisterClass(&The_Class) == 0) throw spica::Win32::API_Error("Failed to register the frame window class"); // Now define appropriate classes for the MDI client windows. The_Class.style = CS_HREDRAW | CS_VREDRAW; The_Class.lpfnWndProc = Topic_Procedure; The_Class.cbClsExtra = 0; The_Class.cbWndExtra = 0; The_Class.hInstance = Global::Get_Instance(); The_Class.hIcon = LoadIcon(Global::Get_Instance(), MAKEINTRESOURCE(TOPIC_ICON)); The_Class.hCursor = LoadCursor(0, IDC_ARROW); The_Class.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); The_Class.lpszMenuName = 0; The_Class.lpszClassName = Topic_ClassName; if (RegisterClass(&The_Class) == 0) throw spica::Win32::API_Error("Failed to register the topic window class"); The_Class.style = CS_HREDRAW | CS_VREDRAW; The_Class.lpfnWndProc = Notice_Procedure; The_Class.cbClsExtra = 0; The_Class.cbWndExtra = 0; The_Class.hInstance = Global::Get_Instance(); The_Class.hIcon = LoadIcon(Global::Get_Instance(), MAKEINTRESOURCE(NOTICE_ICON)); The_Class.hCursor = LoadCursor(0, IDC_ARROW); The_Class.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); The_Class.lpszMenuName = 0; The_Class.lpszClassName = Notice_ClassName; if (RegisterClass(&The_Class) == 0) throw spica::Win32::API_Error("Failed to register the notice window class"); Tracer(2, "Window classes registered"); }
void XZHydrostatic_UTracer<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { #ifndef ALBANY_KOKKOS_UNDER_DEVELOPMENT for (int cell=0; cell < workset.numCells; ++cell) for (int node=0; node < numNodes; ++node) for (int level=0; level < numLevels; ++level) for (int dim=0; dim < numDims; ++dim) { UTracer(cell,node,level,dim) = Velocity(cell,node,level,dim)*Tracer(cell,node,level); //UTracer(cell,node,level,dim) = PiVelx(cell,node,level,dim)*Tracer(cell,node,level); //std::cout << "pivelx: " << cell << " " << node << " " << level << " " << dim << " " << PiVelx(cell,node,level,dim) << std::endl; //std::cout << "Tracer " << Tracer(cell,node,level) << std::endl; } #else Kokkos::parallel_for(XZHydrostatic_UTracer_Policy(0,workset.numCells),*this); #endif }
bool cLineBlockTracer::Trace(cWorld & a_World, cBlockTracer::cCallbacks &a_Callbacks, double a_StartX, double a_StartY, double a_StartZ, double a_EndX, double a_EndY, double a_EndZ) { cLineBlockTracer Tracer(a_World, a_Callbacks); return Tracer.Trace(a_StartX, a_StartY, a_StartZ, a_EndX, a_EndY, a_EndZ); }
Test(const string& s) : val(Tracer(s)) { }
bool cLineBlockTracer::Trace(cWorld & a_World, cBlockTracer::cCallbacks & a_Callbacks, const Vector3d & a_Start, const Vector3d & a_End) { cLineBlockTracer Tracer(a_World, a_Callbacks); return Tracer.Trace(a_Start.x, a_Start.y, a_Start.z, a_End.x, a_End.y, a_End.z); }
// // This window procedure handles messages that are sent to the topic // window. // LRESULT CALLBACK Topic_Procedure( HWND Topic_Window, UINT Message, WPARAM wParam, LPARAM lParam ) { static HWND SubtopicLV_Handle; static HWND NoticeLV_Handle; static bool Application_Closing = false; try { switch (Message) { case WM_CREATE: { Tracer(2, "Processing WM_CREATE for the topic window."); SubtopicLV_Handle = Create_SubtopicLV(Global::Get_Instance(), Topic_Window); NoticeLV_Handle = Create_NoticeLV(Global::Get_Instance(), Topic_Window); Current_Topic->Populate_SubtopicLV(SubtopicLV_Handle); Current_Topic->Populate_NoticeLV(NoticeLV_Handle, History_Database); spica::String Title = "Topic: "; Title.append(Current_Topic->Description()); SetWindowText(Topic_Window, Title); } return 0; // If the topic window is resized, we need to resize the list // views. NOTE: For some reason doing this causes the // min/max/close controls on the topic window to disappear when // the window is maximized. This needs to be fixed sometime. // case WM_SIZE: { Tracer(2, "Processing WM_SIZE for the topic window."); int Width = LOWORD(lParam); int Height = HIWORD(lParam); MoveWindow(SubtopicLV_Handle, 0, Height/2, Width, Height/2, TRUE); MoveWindow(NoticeLV_Handle, 0, 0, Width, Height/2, TRUE); } return 0; // The application is shutting down. All MDI child windows are // queried and then closed. We will use this fact to distinguish // between an application close and the user trying to close // just the topic window. This case returns 1 to indicate that // closing is "okay." // case WM_QUERYENDSESSION: Application_Closing = true; return 1; // Ignore all attempts to close the topic window unless the // entire application is shutting down. // case WM_CLOSE: if (Application_Closing) DestroyWindow(Topic_Window); else MessageBox(Topic_Window, "Topic window can not be closed", "Error", MB_ICONEXCLAMATION); return 0; // This message is sent to us (by the frame window) when we are // supposed to check off all the notices in the child notice // list view. // case WM_USER: Check_All(NoticeLV_Handle); return 0; // This message is sent to us by the child list view controls. case WM_NOTIFY: { int ID = wParam; NM_LISTVIEW *pNM = reinterpret_cast<NM_LISTVIEW *>(lParam); // Is the subtopic listview trying to notify me? if (ID == 1) { // What has happened? switch (pNM->hdr.code) { // We double clicked in it. Try to switch to the subtopic. case NM_DBLCLK: { Tracer(3, "Processing NM_DBLCLK in the subtopic listview."); NB_Topic *New_Topic = Current_Topic->Lookup_Subtopic(SubtopicLV_Handle); if (New_Topic != 0) { ListView_DeleteAllItems(SubtopicLV_Handle); ListView_DeleteAllItems(NoticeLV_Handle); New_Topic->Populate_SubtopicLV(SubtopicLV_Handle); New_Topic->Populate_NoticeLV(NoticeLV_Handle, History_Database); Current_Topic = New_Topic; spica::String Title = "Topic: "; Title.append(Current_Topic->Description()); SetWindowText(Topic_Window, Title); } } return 0; } } // Is the notice listview trying to notify me? if (ID == 2) { // What has happened? switch (pNM->hdr.code) { // We double clicked in it. Open the notice. case NM_DBLCLK: { Tracer(3, "Processing NM_DBLCLK in the notice listview."); static HWND Notice_Handle; NB_Notice *Old = Current_Notice; Current_Notice = Current_Topic->Lookup_Notice(NoticeLV_Handle); if (Current_Notice == 0) Current_Notice = Old; if (Current_Notice == Old) return 0; // If this is the first time the window has appeared, then create it. if (Old == 0) { MDICREATESTRUCT MDI_Create; RECT Client_Rect; HWND Client_Window = GetParent(Topic_Window); GetClientRect(Client_Window, &Client_Rect); MDI_Create.szClass = Notice_ClassName; MDI_Create.szTitle = "Notice Window"; MDI_Create.hOwner = Global::Get_Instance(); MDI_Create.x = Client_Rect.right/2; MDI_Create.y = 0; MDI_Create.cx = Client_Rect.right/2; MDI_Create.cy = Client_Rect.bottom; MDI_Create.style = WS_HSCROLL | WS_VSCROLL; MDI_Create.lParam = 0; Notice_Handle = reinterpret_cast<HWND>(SendMessage(Client_Window, WM_MDICREATE, 0, reinterpret_cast<LPARAM>(&MDI_Create))); if (Notice_Handle == 0) throw spica::Win32::API_Error("Can't create the notice window"); Tracer(3, "Finished creating the notice window."); } Current_Notice->Mark_AsRead(History_Database); // Make sure the notice window gets drawn. InvalidateRect(Notice_Handle, 0, TRUE); } return 0; } } // End of if (ID == 2) ... } // End of WM_NOTIFY case. return 0; } // End of outer switch statement. } catch(spica::Win32::API_Error We) { spica::Win32::notifystream Error_Message; Error_Message << "Exception caught in the topic window\r" << We.what() << ends; Error_Message.say(Topic_Window); return 0; } catch (...) { spica::Win32::notifystream Error_Message; Error_Message << "Unknown exception caught in the topic window" << ends; Error_Message.say(Topic_Window); return 0; } return DefMDIChildProc(Topic_Window, Message, wParam, lParam); }
// // Notice_Procedure // // This window procedure handles messages that are sent to a notice window. // LRESULT CALLBACK Notice_Procedure( HWND Notice_Window, UINT Message, WPARAM wParam, LPARAM lParam ) { static int Char_Height; static int Char_Width; static bool HaveTextInfo = false; try { if (!HaveTextInfo) { TEXTMETRIC Text_Metrics; HDC Context_Handle; Tracer(2, "Getting font size information in the notice window."); Context_Handle = GetDC(Notice_Window); SelectObject(Context_Handle, GetStockObject(OEM_FIXED_FONT)); GetTextMetrics(Context_Handle, &Text_Metrics); Char_Height = Text_Metrics.tmHeight + Text_Metrics.tmExternalLeading; Char_Width = Text_Metrics.tmAveCharWidth; ReleaseDC(Notice_Window, Context_Handle); HaveTextInfo = true; } switch (Message) { case WM_PAINT: { spica::Win32::Paint_Context Painter(Notice_Window); if (Current_Notice != 0) Current_Notice->Redraw(Notice_Window, Painter); } return 0; case WM_HSCROLL: { Tracer(2, "Processing WM_HSCROLL in the notice window."); if (Current_Notice != 0) Current_Notice->HScroll(Notice_Window, wParam, Char_Width); } return 0; case WM_VSCROLL: { Tracer(2, "Processing WM_VSCROLL in the notice window."); if (Current_Notice != 0) Current_Notice->VScroll(Notice_Window, wParam, Char_Height); } return 0; case WM_CLOSE: Current_Notice = 0; DestroyWindow(Notice_Window); return 0; } } catch (spica::Win32::API_Error We) { spica::Win32::notifystream Error_Message; Error_Message << "Exception caught in the notice window\r" << We.what() << ends; Error_Message.say(Notice_Window); return 0; } catch (...) { spica::Win32::notifystream Error_Message; Error_Message << "Unknown exception caught in the notice window" << ends; Error_Message.say(Notice_Window); return 0; } return DefMDIChildProc(Notice_Window, Message, wParam, lParam); }
// // Main Program // int WINAPI WinMain( HINSTANCE Instance, HINSTANCE /* Previous_Instance */, LPSTR Command_Line, int Command_Show ) { HWND Frame_Window; // Handle to the main application window. HWND Client_Window; // Handle to the MDI client window (the workspace). MSG Message; try { // Initialize global data as needed. Global::Set_Instance(Instance); Global::Set_CommandLine(Command_Line); Global::Set_CommandShow(Command_Show); // These strings are initialized here to be sure the "Big String Lock" // has been initialized before these Strings are constructed. Also for // the destructor (actually these strings are currently not destoryed. // Version_Number = new spica::String("1.0"); Full_Name = new spica::String; Email_Address = new spica::String; Tracer(1, "NBread initializing..."); // Read the registry to see how we are configured (or dialog with the user). Check_Configuration(); string *Top_Path = spica::lookup_parameter("Noticeboard_Root"); if (Top_Path == 0) throw spica::Win32::API_Error("Can't locate the noticeboard directory tree"); // This object manages the read notice database (the "history"). // It must be created before any topic is created because the // topic's constructor will reference this database. Similarly // this object must persist after all topics have been destroyed // to insure that the most up to date history file will be written // back to disk. // History Read_Notices; History_Database = &Read_Notices; // This object represents the top level topic. All the subtopics // and notices are contained in this object. When this object is // destroyed all the contained objects and subobects will also be // destroyed. // NB_Topic Top_Level(Top_Path->c_str()); Current_Topic = &Top_Level; // Set up the various window classes that we'll need. Set_Classes(); InitCommonControls(); // Create a main window and display it. Frame_Window = CreateWindow( Frame_ClassName, "VTC Noticeboard Reader", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, Instance, 0 ); if (Frame_Window == 0) throw spica::Win32::API_Error("Can't create the frame window"); Tracer(1, "Finished creating the MDI frame window."); // Get the MDI client window's handle. Client_Window = GetWindow(Frame_Window, GW_CHILD); ShowWindow(Frame_Window, Command_Show); UpdateWindow(Frame_Window); Tracer(1, "Entering main message dispatching loop..."); // Get the next message from the application's message queue. while (GetMessage(&Message, 0, 0, 0)) { if (!TranslateMDISysAccel(Client_Window, &Message)) { TranslateMessage(&Message); DispatchMessage(&Message); } } } catch (spica::Win32::API_Error We) { spica::Win32::notifystream Error_Message; Error_Message << "Exception caught in WinMain\r" << We.what() << ends; Error_Message.say(); return FALSE; } catch (...) { spica::Win32::notifystream Error_Message; Error_Message << "Unknown exception caught in WinMain" << ends; Error_Message.say(); return FALSE; } return Message.wParam; }
// // Frame_Procedure // // This window procedure handles messages that are sent to the frame // window (the window for the entire application). // LRESULT CALLBACK Frame_Procedure( HWND Frame_Window, UINT Message, WPARAM wParam, LPARAM lParam ) { static HWND Topic_Window; static HWND Client_Window; try { switch (Message) { case WM_CREATE: { Tracer(2, "Processing WM_CREATE in the MDI frame window."); // Create the image list that I need. Image_Handle = ImageList_Create(16, 16, ILC_COLOR4 | ILC_MASK, 2, 0); if (Image_Handle == 0) throw spica::Win32::API_Error("Can't create image list"); // Get the icon resources from the executable file. Note // that under Win32 we don't have to explicitly destory // these resources. // HICON UnChecked = static_cast<HICON>( LoadImage(Global::Get_Instance(), MAKEINTRESOURCE(UNCHECKED_ICON), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR)); if (UnChecked == 0) throw spica::Win32::API_Error("Can't load UNCHECKED_ICON"); HICON Checked = static_cast<HICON>( LoadImage(Global::Get_Instance(), MAKEINTRESOURCE(CHECKED_ICON), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR)); if (Checked == 0) throw spica::Win32::API_Error("Can't load CHECKED_ICON"); // Add the images to the image list. if (ImageList_AddIcon(Image_Handle, UnChecked) == -1) throw spica::Win32::API_Error("Can't add UNCHECKED_ICON to the image list"); if (ImageList_AddIcon(Image_Handle, Checked) == -1) throw spica::Win32::API_Error("Can't add CHECKED_ICON to the image list"); // Create the MDI client window. CLIENTCREATESTRUCT Client_Create; RECT Frame_Rect; Client_Create.hWindowMenu = 0; Client_Create.idFirstChild = 100; // Create the MDI client window. Client_Window = CreateWindow( "MDICLIENT", 0, WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE, 0, 0, 0, 0, Frame_Window, reinterpret_cast<HMENU>(1), Global::Get_Instance(), reinterpret_cast<LPVOID>(&Client_Create) ); if (Client_Window == 0) throw spica::Win32::API_Error("Can't create the MDI client window"); Tracer(2, "Finished creating the MDI client window."); // Create the topic window. GetClientRect(Frame_Window, &Frame_Rect); Topic_Window = CreateMDIWindow( const_cast<char *>(Topic_ClassName), "Topic Window", WS_CHILD | WS_VISIBLE, 0, 0, Frame_Rect.right/2, Frame_Rect.bottom, Client_Window, Global::Get_Instance(), 0 ); if (Topic_Window == 0) throw spica::Win32::API_Error("Can't create the topic window"); Tracer(2, "Finished creating the topic window."); } return 0; // A menu item was selected. case WM_COMMAND: switch (wParam) { case MENU_CONFIGURE: { Tracer(2, "Selected 'File|Configure' menu item."); DialogBox(Global::Get_Instance(), MAKEINTRESOURCE(CONFIG_DIALOG), Frame_Window, Config_Dialog); } return 0; case MENU_EXIT: { Tracer(2, "Selected 'File|Exit' menu item."); DestroyWindow(Frame_Window); } return 0; case MENU_POST: { Tracer(2, "Selected 'Topic|Post' menu item."); DialogBox(Global::Get_Instance(), MAKEINTRESOURCE(POST_DIALOG), Frame_Window, Post_Dialog); } return 0; case MENU_MARKALL: { Tracer(2, "Selected 'Topic|Mark All As Read' menu item."); Current_Topic->Mark_All(History_Database); SendMessage(Topic_Window, WM_USER, 0, 0); } return 0; case MENU_MARKSELECTED: { Tracer(2, "Selected 'Topic|Mark Selected As Read' menu item."); MessageBox(Frame_Window, "Not Implemented", "Sorry", MB_ICONEXCLAMATION); } return 0; case MENU_FOLLOWUP: { Tracer(2, "Selected 'Notice|Followup' menu item."); MessageBox(Frame_Window, "Not Implemented", "Sorry", MB_ICONEXCLAMATION); } return 0; case MENU_DEBUG: { Tracer(2, "Selected 'Debug' menu item."); spica::Win32::create_debugWindow(); } return 0; case MENU_TILE: { Tracer(2, "Selected 'Window|Tile' menu item."); SendMessage(Client_Window, WM_MDITILE, 0, 0); } return 0; case MENU_CASCADE: { Tracer(2, "Selected 'Window|Cascade' menu item."); SendMessage(Client_Window, WM_MDICASCADE, 0, 0); } return 0; case MENU_ARRANGE: { Tracer(2, "Selected 'Window|Arrange' menu item."); SendMessage(Client_Window, WM_MDIICONARRANGE, 0, 0); } return 0; case MENU_HELP: { Tracer(2, "Selected 'Help' menu item."); MessageBox(Frame_Window, "Not Implemented", "Sorry", MB_ICONEXCLAMATION); } return 0; default: { Tracer(2, "Other WM_COMMAND seen. Sending to active MDI child window."); HWND MDIChild_Window = reinterpret_cast<HWND>(SendMessage(Client_Window, WM_MDIGETACTIVE, 0, 0)); if (IsWindow(MDIChild_Window)) SendMessage(MDIChild_Window, WM_COMMAND, wParam, lParam); break; } } break; // The user is trying to close the application (or shut down Windows). case WM_QUERYENDSESSION: case WM_CLOSE: // Try to close all the children. EnumChildWindows(Client_Window, Close_Childs, 0); // If it didn't work, return 0. Otherwise call DefFrameProc(). if (GetWindow(Client_Window, GW_CHILD) != 0) return 0; break; // The main window is being destroyed. case WM_DESTROY: ImageList_Destroy(Image_Handle); PostQuitMessage(0); return 0; } } catch (spica::Win32::API_Error We) { spica::Win32::notifystream Error_Message; Error_Message << "Exception caught in the frame window\r" << We.what() << ends; Error_Message.say(Frame_Window); return 0; } catch (...) { spica::Win32::notifystream Error_Message; Error_Message << "Unknown exception caught in the frame window" << ends; Error_Message.say(Frame_Window); return 0; } return DefFrameProc(Frame_Window, Client_Window, Message, wParam, lParam); }
void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { // TODO Add collision detection with entities. a_Dt /= 1000; // Convert from msec to sec Vector3d NextPos = Vector3d(GetPosX(),GetPosY(),GetPosZ()); Vector3d NextSpeed = Vector3d(GetSpeedX(),GetSpeedY(),GetSpeedZ()); int BlockX = (int) floor(NextPos.x); int BlockY = (int) floor(NextPos.y); int BlockZ = (int) floor(NextPos.z); if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { // Outside of the world cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); // See if we can commit our changes. If not, we will discard them. if (NextChunk != NULL) { SetSpeed(NextSpeed); NextPos += (NextSpeed * a_Dt); SetPosition(NextPos); } return; } // Make sure we got the correct chunk and a valid one. No one ever knows... cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); if (NextChunk != NULL) { int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; if (!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block { if (m_bOnGround) // check if it's still on the ground { if (!g_BlockIsSolid[BlockBelow]) // Check if block below is air or water. { m_bOnGround = false; } } } else { // Push out entity. BLOCKTYPE GotBlock; static const struct { int x, y, z; } gCrossCoords[] = { { 1, 0, 0}, {-1, 0, 0}, { 0, 0, 1}, { 0, 0, -1}, } ; bool IsNoAirSurrounding = true; for (int i = 0; i < ARRAYCOUNT(gCrossCoords); i++) { if (!NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock)) { // The pickup is too close to an unloaded chunk, bail out of any physics handling return; } if (!g_BlockIsSolid[GotBlock]) { NextPos.x += gCrossCoords[i].x; NextPos.z += gCrossCoords[i].z; IsNoAirSurrounding = false; break; } } // for i - gCrossCoords[] if (IsNoAirSurrounding) { NextPos.y += 0.5; } m_bOnGround = true; LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}", m_UniqueID, GetClass(), BlockX, BlockY, BlockZ ); } if (!m_bOnGround) { float fallspeed; if (IsBlockWater(BlockIn)) { fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water. } else if (IsBlockRail(BlockBelow) && IsMinecart()) // Rails aren't solid, except for Minecarts { fallspeed = 0; m_bOnGround = true; } else if (BlockIn == E_BLOCK_COBWEB) { NextSpeed.y *= 0.05; // Reduce overall falling speed fallspeed = 0; // No falling. } else { // Normal gravity fallspeed = m_Gravity * a_Dt; } NextSpeed.y += fallspeed; } else { if (IsMinecart()) { if (!IsBlockRail(BlockBelow)) { // Friction if minecart is off track, otherwise, Minecart.cpp handles this if (NextSpeed.SqrLength() > 0.0004f) { NextSpeed.x *= 0.7f / (1 + a_Dt); if (fabs(NextSpeed.x) < 0.05) { NextSpeed.x = 0; } NextSpeed.z *= 0.7f / (1 + a_Dt); if (fabs(NextSpeed.z) < 0.05) { NextSpeed.z = 0; } } } } else { // Friction for non-minecarts if (NextSpeed.SqrLength() > 0.0004f) { NextSpeed.x *= 0.7f / (1 + a_Dt); if (fabs(NextSpeed.x) < 0.05) { NextSpeed.x = 0; } NextSpeed.z *= 0.7f / (1 + a_Dt); if (fabs(NextSpeed.z) < 0.05) { NextSpeed.z = 0; } } } } // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we // might have different speed modifiers according to terrain. if (BlockIn == E_BLOCK_COBWEB) { NextSpeed.x *= 0.25; NextSpeed.z *= 0.25; } //Get water direction Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ); m_WaterSpeed *= 0.9f; //Reduce speed each tick switch(WaterDir) { case X_PLUS: m_WaterSpeed.x = 0.2f; m_bOnGround = false; break; case X_MINUS: m_WaterSpeed.x = -0.2f; m_bOnGround = false; break; case Z_PLUS: m_WaterSpeed.z = 0.2f; m_bOnGround = false; break; case Z_MINUS: m_WaterSpeed.z = -0.2f; m_bOnGround = false; break; default: break; } if (fabs(m_WaterSpeed.x) < 0.05) { m_WaterSpeed.x = 0; } if (fabs(m_WaterSpeed.z) < 0.05) { m_WaterSpeed.z = 0; } NextSpeed += m_WaterSpeed; if( NextSpeed.SqrLength() > 0.f ) { cTracer Tracer( GetWorld() ); int Ret = Tracer.Trace( NextPos, NextSpeed, 2 ); if( Ret ) // Oh noez! we hit something { // Set to hit position if( (Tracer.RealHit - NextPos).SqrLength() <= ( NextSpeed * a_Dt ).SqrLength() ) { if( Ret == 1 ) { if( Tracer.HitNormal.x != 0.f ) NextSpeed.x = 0.f; if( Tracer.HitNormal.y != 0.f ) NextSpeed.y = 0.f; if( Tracer.HitNormal.z != 0.f ) NextSpeed.z = 0.f; if( Tracer.HitNormal.y > 0 ) // means on ground { m_bOnGround = true; } } NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z); NextPos.x += Tracer.HitNormal.x * 0.3f; NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot NextPos.z += Tracer.HitNormal.z * 0.3f; } else { NextPos += (NextSpeed * a_Dt); } } else { // We didn't hit anything, so move =] NextPos += (NextSpeed * a_Dt); } } BlockX = (int) floor(NextPos.x); BlockZ = (int) floor(NextPos.z); NextChunk = NextChunk->GetNeighborChunk(BlockX,BlockZ); // See if we can commit our changes. If not, we will discard them. if (NextChunk != NULL) { if (NextPos.x != GetPosX()) SetPosX(NextPos.x); if (NextPos.y != GetPosY()) SetPosY(NextPos.y); if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z); if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x); if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y); if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z); } } }
// // Create_NoticeLV // // This function creates a listview control within the topic window. The // listview will contain all the notices. This function returns the // handle of the list view control. // static HWND Create_NoticeLV(HINSTANCE Instance, HWND Topic_Window) { RECT Topic_Rect; LV_COLUMN Col; HWND List_Window; GetClientRect(Topic_Window, &Topic_Rect); List_Window = CreateWindowEx( 0, WC_LISTVIEW, "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | LVS_REPORT | LVS_SHAREIMAGELISTS, 0, 0, Topic_Rect.right, Topic_Rect.bottom, Topic_Window, reinterpret_cast<HMENU>(2), Instance, 0 ); if (List_Window == 0) throw spica::Win32::API_Error("Can't create the notice listview"); #ifdef NEVER // Associate the image list with the list view. if (ListView_SetImageList(List_Window, Image_Handle, LVSIL_SMALL) == 0) // throw spica::Win32::Windows_Error("Can't associate image list with the notice list view"); /* Do nothing. ListView_SetImageList() appears to always return NULL */ ; #endif Col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; Col.fmt = LVCFMT_LEFT; Col.cx = Topic_Rect.right/3; Col.pszText = "Subject"; Col.iSubItem = 0; int Err; Err = ListView_InsertColumn(List_Window, 0, &Col); if (Err == -1) throw spica::Win32::API_Error("Can't insert 'From' column into the notice listview"); Col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; Col.fmt = LVCFMT_LEFT; Col.cx = Topic_Rect.right/3; Col.pszText = "From"; Col.iSubItem = 1; Err = ListView_InsertColumn(List_Window, 1, &Col); if (Err == -1) throw spica::Win32::API_Error("Can't insert 'Subject' column into the notice listview"); Col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; Col.fmt = LVCFMT_LEFT; Col.cx = Topic_Rect.right/3; Col.pszText = "Date & Time"; Col.iSubItem = 2; Err = ListView_InsertColumn(List_Window, 2, &Col); if (Err == -1) throw spica::Win32::API_Error("Can't insert 'Date & Time' column into the notice listview"); Tracer(3, "Finished creating the notice listview."); return List_Window; }
/*virtual*/ void_t Test_Condition::unit( culonglong_t &a_caseLoops ) { xUNUSED(a_caseLoops); #if xENV_UNIX && xTODO int_t iRv = - 1; pthread_t thThreads[3] = {0}; clong_t liId1 = 1L; clong_t liId2 = 2L; clong_t liId3 = 3L; // initialize { iRv = ::pthread_mutex_init(&g_mtMutex, xPTR_NULL); // mutex not recursive xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_cond_init(&g_cndCondition, xPTR_NULL); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); // for portability, explicitly create threads in a joinable state pthread_attr_t atAttr /* = {{0}} */; iRv = ::pthread_attr_init(&atAttr); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_attr_setdetachstate(&atAttr, PTHREAD_CREATE_JOINABLE); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_create(&thThreads[0], &atAttr, pvWatch, (void_t *)&liId1); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_create(&thThreads[1], &atAttr, pvJob, (void_t *)&liId2); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_create(&thThreads[2], &atAttr, pvJob, (void_t *)&liId3); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_attr_destroy(&atAttr); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); } // wait for all threads to complete for (size_t i = 0; i < g_cuiThreadsNum; ++ i) { iRv = ::pthread_join(thThreads[i], xPTR_NULL); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); } #if 0 Tracer() << xT("Main(): waited on ") << g_cuiThreadsNum << xT(" threads. Done"); #endif // clean up { iRv = ::pthread_cond_destroy(&g_cndCondition); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); iRv = ::pthread_mutex_destroy(&g_mtMutex); xTEST_MSG_EQ(0, iRv, NativeError::format(iRv)); } // ::exit(0); #if xTEMP_DISABLED Condition cond; cond.mutex(); cond.handle(); cond.create(); cond.wait(5000UL); cond.signal(); cond.broadcast(); #endif #endif // xENV_UNIX }
void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { int BlockX = POSX_TOINT; int BlockY = POSY_TOINT; int BlockZ = POSZ_TOINT; // Position changed -> super::HandlePhysics() called GET_AND_VERIFY_CURRENT_CHUNK(NextChunk, BlockX, BlockZ) // TODO Add collision detection with entities. a_Dt /= 1000; // Convert from msec to sec Vector3d NextPos = Vector3d(GetPosX(), GetPosY(), GetPosZ()); Vector3d NextSpeed = Vector3d(GetSpeedX(), GetSpeedY(), GetSpeedZ()); if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { // Outside of the world AddSpeedY(m_Gravity * a_Dt); AddPosition(GetSpeed() * a_Dt); return; } int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block { if (m_bOnGround) // check if it's still on the ground { if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water. { m_bOnGround = false; } } } else { // Push out entity. BLOCKTYPE GotBlock; static const struct { int x, y, z; } gCrossCoords[] = { { 1, 0, 0}, {-1, 0, 0}, { 0, 0, 1}, { 0, 0, -1}, } ; bool IsNoAirSurrounding = true; for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) { if (!NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock)) { // The pickup is too close to an unloaded chunk, bail out of any physics handling return; } if (!cBlockInfo::IsSolid(GotBlock)) { NextPos.x += gCrossCoords[i].x; NextPos.z += gCrossCoords[i].z; IsNoAirSurrounding = false; break; } } // for i - gCrossCoords[] if (IsNoAirSurrounding) { NextPos.y += 0.5; } m_bOnGround = true; /* // DEBUG: LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}", m_UniqueID, GetClass(), BlockX, BlockY, BlockZ ); */ } if (!m_bOnGround) { float fallspeed; if (IsBlockWater(BlockIn)) { fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water. } else if (BlockIn == E_BLOCK_COBWEB) { NextSpeed.y *= 0.05; // Reduce overall falling speed fallspeed = 0; // No falling. } else { // Normal gravity fallspeed = m_Gravity * a_Dt; } NextSpeed.y += fallspeed; } else { // Friction if (NextSpeed.SqrLength() > 0.0004f) { NextSpeed.x *= 0.7f / (1 + a_Dt); if (fabs(NextSpeed.x) < 0.05) { NextSpeed.x = 0; } NextSpeed.z *= 0.7f / (1 + a_Dt); if (fabs(NextSpeed.z) < 0.05) { NextSpeed.z = 0; } } } // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we // might have different speed modifiers according to terrain. if (BlockIn == E_BLOCK_COBWEB) { NextSpeed.x *= 0.25; NextSpeed.z *= 0.25; } //Get water direction Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ); m_WaterSpeed *= 0.9f; //Reduce speed each tick switch(WaterDir) { case X_PLUS: m_WaterSpeed.x = 0.2f; m_bOnGround = false; break; case X_MINUS: m_WaterSpeed.x = -0.2f; m_bOnGround = false; break; case Z_PLUS: m_WaterSpeed.z = 0.2f; m_bOnGround = false; break; case Z_MINUS: m_WaterSpeed.z = -0.2f; m_bOnGround = false; break; default: break; } if (fabs(m_WaterSpeed.x) < 0.05) { m_WaterSpeed.x = 0; } if (fabs(m_WaterSpeed.z) < 0.05) { m_WaterSpeed.z = 0; } NextSpeed += m_WaterSpeed; if (NextSpeed.SqrLength() > 0.f) { cTracer Tracer(GetWorld()); // Distance traced is an integer, so we round up from the distance we should go (Speed * Delta), else we will encounter collision detection failurse int DistanceToTrace = (int)(ceil((NextSpeed * a_Dt).SqrLength()) * 2); bool HasHit = Tracer.Trace(NextPos, NextSpeed, DistanceToTrace); if (HasHit) { // Oh noez! We hit something: verify that the (hit position - current) was smaller or equal to the (position that we should travel without obstacles - current) // This is because previously, we traced with a length that was rounded up (due to integer limitations), and in the case that something was hit, we don't want to overshoot our projected movement if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * a_Dt).SqrLength()) { // Block hit was within our projected path // Begin by stopping movement in the direction that we hit something. The Normal is the line perpendicular to a 2D face and in this case, stores what block face was hit through either -1 or 1. // For example: HitNormal.y = -1 : BLOCK_FACE_YM; HitNormal.y = 1 : BLOCK_FACE_YP if (Tracer.HitNormal.x != 0.f) NextSpeed.x = 0.f; if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f; if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f; if (Tracer.HitNormal.y == 1) // Hit BLOCK_FACE_YP, we are on the ground { m_bOnGround = true; } // Now, set our position to the hit block (i.e. move part way along our intended trajectory) NextPos.Set(Tracer.RealHit.x, Tracer.RealHit.y, Tracer.RealHit.z); NextPos.x += Tracer.HitNormal.x * 0.1; NextPos.y += Tracer.HitNormal.y * 0.05; NextPos.z += Tracer.HitNormal.z * 0.1; } else { // We have hit a block but overshot our intended trajectory, move normally, safe in the warm cocoon of knowledge that we won't appear to teleport forwards on clients, // and that this piece of software will come to be hailed as the epitome of performance and functionality in C++, never before seen, and of such a like that will never // be henceforth seen again in the time of programmers and man alike // </&sensationalist> NextPos += (NextSpeed * a_Dt); } } else { // We didn't hit anything, so move =] NextPos += (NextSpeed * a_Dt); } } SetPosition(NextPos); SetSpeed(NextSpeed); }
void TracerManager::registerTracer(const string &fileName, const MeshManager &meshManager) { // ------------------------------------------------------------------------- // parse and read file NcError ncError(NcError::silent_nonfatal); NcFile file(fileName.c_str(), NcFile::ReadOnly); if (!file.is_valid()) { Message message; message << "Failed to open tracer file \"" << fileName << "\"!"; REPORT_ERROR(message.str()); } if (file.get_att("name") == NULL) { Message message; message << "There is no \"name\" attribute in tracer file \""; message << fileName << "\"!"; REPORT_ERROR(message.str()); } tracerNames.push_back(file.get_att("name")->as_string(0)); if (file.get_att("name") == NULL) { Message message; message << "There is no \"name\" attribute in tracer file \""; message << fileName << "\"!"; REPORT_ERROR(message.str()); } tracerNames.push_back(file.get_att("name")->as_string(0)); int numPolygon = static_cast<int>(file.get_dim("num_total_polygon")->size()); if (numPolygon != polygonManager.polygons.size()) { Message message; message << "Polygon numbers (" << numPolygon << " != "; message << polygonManager.polygons.size(); message << ") are not consistent in tracer file \""; message << fileName << "\"!"; REPORT_ERROR(message.str()); } double mass[numPolygon]; if (file.get_var("mass") == NULL) { Message message; message << "There is no \"mass\" variable in tracer file \""; message << fileName << "\"!"; REPORT_ERROR(message.str()); } file.get_var("mass")->get(mass); // ------------------------------------------------------------------------- // initialize tracer density on the mesh tracerDensities.push_back(Field()); if (meshManager.hasLayers()) tracerDensities.back().init(meshManager.getMesh(PointCounter::Center), meshManager.getMesh(PointCounter::Bound), meshManager.getLayers(Layers::Full)); else tracerDensities.back().init(meshManager.getMesh(PointCounter::Center), meshManager.getMesh(PointCounter::Bound)); // ------------------------------------------------------------------------- // set up tracer variables in polygons int tracerId = static_cast<int>(tracerNames.size()-1); Polygon *polygon = polygonManager.polygons.front(); for (int i = 0; i < polygonManager.polygons.size(); ++i) { polygon->tracers.push_back(Tracer()); polygon->tracers[tracerId].setMass(mass[i]); polygon = polygon->next; } }
void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { // TODO Add collision detection with entities. a_Dt /= 1000; Vector3d NextPos = Vector3d(GetPosX(),GetPosY(),GetPosZ()); Vector3d NextSpeed = Vector3d(GetSpeedX(),GetSpeedY(),GetSpeedZ()); int BlockX = (int) floor(NextPos.x); int BlockY = (int) floor(NextPos.y); int BlockZ = (int) floor(NextPos.z); if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { // Outside of the world // TODO: Current speed should still be added to the entity position // Otherwise TNT explosions in the void will still effect the bottommost layers of the world return; } // Make sure we got the correct chunk and a valid one. No one ever knows... cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX,BlockZ); if (NextChunk != NULL) { int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); if (!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block { if (m_bOnGround) // check if it's still on the ground { BLOCKTYPE BlockBelow = NextChunk->GetBlock( RelBlockX, BlockY - 1, RelBlockZ ); if (!g_BlockIsSolid[BlockBelow]) // Check if block below is air or water. { m_bOnGround = false; } } } else { //Push out entity. m_bOnGround = true; NextPos.y += 0.2; LOGD("Entity #%d (%s) is inside a block at {%d,%d,%d}", m_UniqueID, GetClass(), BlockX, BlockY, BlockZ); } if (!m_bOnGround) { float fallspeed; if (IsBlockWater(BlockIn)) { fallspeed = -3.0f * a_Dt; //Fall slower in water. } else if (BlockIn == E_BLOCK_COBWEB) { NextSpeed.y *= 0.05; //Reduce overall falling speed fallspeed = 0; //No falling. } else { //Normal gravity fallspeed = m_Gravity * a_Dt; } NextSpeed.y += fallspeed; } else { //Friction if (NextSpeed.SqrLength() > 0.0004f) { NextSpeed.x *= 0.7f/(1+a_Dt); if ( fabs(NextSpeed.x) < 0.05 ) NextSpeed.x = 0; NextSpeed.z *= 0.7f/(1+a_Dt); if ( fabs(NextSpeed.z) < 0.05 ) NextSpeed.z = 0; } } //Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we //might have different speed modifiers according to terrain. if (BlockIn == E_BLOCK_COBWEB) { NextSpeed.x *= 0.25; NextSpeed.z *= 0.25; } //Get water direction Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ); m_WaterSpeed *= 0.9f; //Reduce speed each tick switch(WaterDir) { case X_PLUS: m_WaterSpeed.x = 1.f; m_bOnGround = false; break; case X_MINUS: m_WaterSpeed.x = -1.f; m_bOnGround = false; break; case Z_PLUS: m_WaterSpeed.z = 1.f; m_bOnGround = false; break; case Z_MINUS: m_WaterSpeed.z = -1.f; m_bOnGround = false; break; default: break; } if (fabs(m_WaterSpeed.x) < 0.05) { m_WaterSpeed.x = 0; } if (fabs(m_WaterSpeed.z) < 0.05) { m_WaterSpeed.z = 0; } NextSpeed += m_WaterSpeed; if( NextSpeed.SqrLength() > 0.f ) { cTracer Tracer( GetWorld() ); int Ret = Tracer.Trace( NextPos, NextSpeed, 2 ); if( Ret ) // Oh noez! we hit something { // Set to hit position if( (Tracer.RealHit - NextPos).SqrLength() <= ( NextSpeed * a_Dt ).SqrLength() ) { if( Ret == 1 ) { if( Tracer.HitNormal.x != 0.f ) NextSpeed.x = 0.f; if( Tracer.HitNormal.y != 0.f ) NextSpeed.y = 0.f; if( Tracer.HitNormal.z != 0.f ) NextSpeed.z = 0.f; if( Tracer.HitNormal.y > 0 ) // means on ground { m_bOnGround = true; } } NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z); NextPos.x += Tracer.HitNormal.x * 0.5f; NextPos.z += Tracer.HitNormal.z * 0.5f; } else NextPos += (NextSpeed * a_Dt); } else { // We didn't hit anything, so move =] NextPos += (NextSpeed * a_Dt); } } BlockX = (int) floor(NextPos.x); BlockZ = (int) floor(NextPos.z); NextChunk = NextChunk->GetNeighborChunk(BlockX,BlockZ); // See if we can commit our changes. If not, we will discard them. if (NextChunk != NULL) { if (NextPos.x != GetPosX()) SetPosX(NextPos.x); if (NextPos.y != GetPosY()) SetPosY(NextPos.y); if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z); if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x); if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y); if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z); } } }
void myDraw(void) { setcolor(1.0F,1.0F,1.0F); switch (bascule) { /* Trace un rectangle rouge a l'ecran si active * par appui de la touche 'a' */ /*setcolor(1.0F,0.0F,0.0F); bar(-0.5F,-0.5F,0.5F,0.5F);*/ case'a': zoom*=1.1; break; case'r': zoom*=0.9; break; case't': //Tracer(tab[0]); break; case'z': DecalageY -= graduation*x*0.1; break; case'q': DecalageX += graduation*x*0.1; break; case's': DecalageY += graduation*x*0.1; break; case'd': DecalageX -= graduation*x*0.1; break; } if(bascule != 'e') { Tracer(tab[0]); } setcolor(1.0F,1.0F,0.0F); outtextxy(-1.0,0.94,"a : Agrandir"); outtextxy(-0.8,0.94,"/ r : Retrecir"); outtextxy(-0.15,0.94,"t : Tracer"); outtextxy(0.03,0.94,"/ e : Effacer"); outtextxy(0.5,0.94,"z : Haut"); outtextxy(-1.0,0.84,"s : Bas"); outtextxy(-0.15,0.84,"q : Gauche"); outtextxy(0.5,0.84,"d : Droite"); char g[10]; sprintf(g,"%.2f",graduation); char aff[23] = "graduation : "; strcat(aff, g); outtextxy(0.6,-0.9, aff); /*Tracage des axes*/ setcolor(1.0F,1.0F,1.0F); // met en couleur la courbe double abs = fabs(Ymin)/(Ymax-Ymin); abs= -x+abs*x*2; line((-1*x)*zoom + DecalageX,(abs)*zoom + DecalageY,(1*x)*zoom + DecalageX,(abs)*zoom + DecalageY);//abscisse double ordo = fabs(Xmin)/(Xmax-Xmin); ordo = -x+ordo*x*2; line((ordo)*zoom + DecalageX,(-1*x)*zoom + DecalageY,(ordo)*zoom + DecalageX,(1*x)*zoom + DecalageY);//ordonné double test1 = (Xmax-Xmin)/graduation; double pasX = x*2/test1; double test2 = (Ymax-Ymin)/graduation; double pasY = x*2/test2; for(float i=0;i<=(x*2);i+=pasX) { line((-x+i)*zoom + DecalageX,(-0.01+abs)*zoom + DecalageY,(-x+i)*zoom + DecalageX,(0.01+abs)*zoom + DecalageY);//grad abscisse } for(float i=0;i<=(x*2);i+=pasY) { line((-0.01+ordo)*zoom + DecalageX,(-x+i)*zoom + DecalageY,(0.01+ordo)*zoom + DecalageX,(-x+i)*zoom + DecalageY);// grad ordonnées } outtextxy(ordo-0.05 + DecalageX,abs-0.05+DecalageY,"0"); }