void CCMessageBox(const char * pszMsg, const char * pszTitle) { #if defined(VLD_DEBUG_MEMORY) VLDReportLeaks(); #endif // Create the message dialog and set its content Platform::String^ message = ref new Platform::String(CCUtf8ToUnicode(pszMsg, -1).c_str()); Platform::String^ title = ref new Platform::String(CCUtf8ToUnicode(pszTitle, -1).c_str()); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) Windows::UI::Popups::MessageDialog^ msg = ref new Windows::UI::Popups::MessageDialog(message, title); // Set the command to be invoked when a user presses 'ESC' msg->CancelCommandIndex = 1; // Show the message dialog msg->ShowAsync(); #else ModalLayer *messageBox = ModalLayer::create(); messageBox->setMessage(pszMsg); CCDirector::sharedDirector()->getRunningScene()->addChild(messageBox); #endif }
int Test() { VLDSetOptions(VLD_OPT_TRACE_INTERNAL_FRAMES | VLD_OPT_SKIP_CRTSTARTUP_LEAKS, 256, 64); void* m = malloc(50); // 8 char* n = new char[60]; // 9 memset(s_m, '1', 10); memset(s_n, '2', 20); memset(g_m, '3', 30); memset(g_n, '4', 40); memset(m, '5', 50); memset(n, '6', 60); // std libary dynamically initializes the objects "cout" and "cerr", which // produce false positive leaks in Release_StaticCrt because we doesn't have // debug CRT allocation header. std::cout << "Test: cout"; //std::cerr << "Test: cerr"; // At this point VLDGetLeaksCount() and VLDReportLeaks() should report 9 leaks // including a leak for ml which has not been freed yet. ml will be freed after // _tmain exits but before VLDReportLeaks() is called internally by VLD and // therefore correctly report 8 leaks. int leaks = VLDGetLeaksCount(); VLDReportLeaks(); // at this point should report 9 leaks; return leaks; }
int main(void) { SetConsoleTitle(TITLE); mtx_init(&gmutex, mtx_plain); cnd_init(&gcond); init_timer(); init_path(); init_strings(); init_server(); initpackets(); //test_map(1); thrd_create(&t1, initsocket, (void*)0); thrd_create(&t2, commands, (void*)0); server_loop(); destroy_server(); mtx_destroy(&gmutex); cnd_destroy(&gcond); #if _DEBUG VLDReportLeaks(); #endif exit(TRUE);// Exit program }
void EventReceiver::checkEvents() { //Need to capture/update each device keyboard->capture(); if (joystick) joystick->capture(); OIS::JoyStickState joystickState; if (joystick) joystickState = joystick->getJoyStickState(); #if 0 if (test_kc == 0) { test_kc = KeyConfig::getKeyConfig(keyboard, joystickState, deadZone, false); if (test_kc) { dprintf(MY_DEBUG_INFO, "test_kc assigned: %d\n", test_kc->key); //assert(0); } } else { float pressed = test_kc->getPercentage(keyboard, joystickState); if (pressed > deadZone) { dprintf(MY_DEBUG_INFO, "test_kc pressed: %f\n", pressed); } } if (keyboard->isKeyDown(OIS::KC_ESCAPE)) { delete test_kc; test_kc = 0; } //printf("%s\n", keyboard->isKeyDown(OIS::KC_K)?"true":"false"); /* printf("Axes: %lu\n", joystickState.mAxes.size()); for (unsigned int i = 0; i < joystickState.mAxes.size(); i++) { printf("\t%u: %d (%d)\n", i, joystickState.mAxes[i].abs, joystickState.mAxes[i].rel); } printf("Sliders:\n"); for (unsigned int i = 0; i < 4; i++) { printf("\t%u: %d, %d\n", i, joystickState.mSliders[i].abX, joystickState.mSliders[i].abY); } */ #else // 0 or 1 if (MenuManager::getInstance()->getMenuInput()) { /* if (IS_PRESSED(SWITCH_INPUT)) { MenuManager::getInstance()->clearEventReceiver(); MenuPageEditor::menuPageEditor->activateAction(); } */ } else { // the real event check // mouse /* mouse->capture(); const OIS::MouseState mouseState = mouse->getMouseState(); if (mouseState.buttonDown(OIS::MB_Left)) { printf("mouse button left down\n"); } if (mouseState.buttonDown(OIS::MB_Right)) { printf("mouse button right down\n"); } if (mouseState.buttonDown(OIS::MB_Middle)) { printf("mouse button middle down\n"); } */ // other float perc = 0.f; if (IS_PRESSED(BRAKE) && (perc = getPercentage(BRAKE, joystickState))/* > Settings::getInstance()->joystickDeadZone*/) { //dprintf(MY_DEBUG_NOTE, "brake pressed: %f\n", perc); Player::getInstance()->setFirstPressed(); Player::getInstance()->getVehicle()->setTorque(perc/*perc*/); } else if (IS_PRESSED(ACCELERATE) && (perc = getPercentage(ACCELERATE, joystickState))/* > Settings::getInstance()->joystickDeadZone*/) { //dprintf(MY_DEBUG_NOTE, "accelerate pressed: %f\n", perc); Player::getInstance()->setFirstPressed(); Player::getInstance()->getVehicle()->setTorque(-1.0f*perc/*perc*/); } else { if (Settings::getInstance()->AIPlayer == false || Settings::getInstance()->editorMode || Player::getInstance()->getStarter() == 0) { Player::getInstance()->getVehicle()->setTorque(0); } } if (Settings::getInstance()->AIPlayer == false || Settings::getInstance()->editorMode || Player::getInstance()->getStarter() == 0) { if (IS_PRESSED(CLUTCH) && (perc = getPercentage(CLUTCH, joystickState))/* > Settings::getInstance()->joystickDeadZone*/) { //dprintf(MY_DEBUG_NOTE, "accelerate pressed: %f\n", perc); Player::getInstance()->getVehicle()->setClutch(perc*perc); } const float steerRatePressed = Settings::getInstance()->steerRatePressed; // 0.2f float steerRate = Settings::getInstance()->steerRate; // 0.5f float desiredSteer = 0.0f; perc = 0.0f; if (Settings::getInstance()->linearSteering) { if (IS_PRESSED(LEFT) && (perc = getPercentage(LEFT, joystickState))/* > Settings::getInstance()->joystickDeadZone*/) { //dprintf(MY_DEBUG_NOTE, "left pressed: %f\n", perc); //Player::getInstance()->getVehicle()->setSteer(-1.0f*perc*perc); desiredSteer = -1.0f*perc; } else if (IS_PRESSED(RIGHT) && (perc = getPercentage(RIGHT, joystickState))/* > Settings::getInstance()->joystickDeadZone*/) { //dprintf(MY_DEBUG_NOTE, "right pressed: %f\n", perc); //Player::getInstance()->getVehicle()->setSteer(perc*perc); desiredSteer = perc; } else { //Player::getInstance()->getVehicle()->setSteer(0.0f); } if (perc > Settings::getInstance()->joystickDeadZone) { steerRate = steerRatePressed; } } else { if (IS_PRESSED(LEFT) && (perc = getPercentage(LEFT, joystickState))/* > Settings::getInstance()->joystickDeadZone*/) { //dprintf(MY_DEBUG_NOTE, "left pressed: %f\n", perc); //Player::getInstance()->getVehicle()->setSteer(-1.0f*perc*perc); desiredSteer = -1.0f*perc*perc; } else if (IS_PRESSED(RIGHT) && (perc = getPercentage(RIGHT, joystickState))/* > Settings::getInstance()->joystickDeadZone*/) { //dprintf(MY_DEBUG_NOTE, "right pressed: %f\n", perc); //Player::getInstance()->getVehicle()->setSteer(perc*perc); desiredSteer = perc*perc; } else { //Player::getInstance()->getVehicle()->setSteer(0.0f); } if (perc*perc > Settings::getInstance()->joystickDeadZone) { steerRate = steerRatePressed; } } //printf("steer rate: %f\n", steerRate); if (lastSteer + steerRate < desiredSteer) { lastSteer += steerRate; } else if (lastSteer - steerRate > desiredSteer) { lastSteer -= steerRate; } else { lastSteer = desiredSteer; } Player::getInstance()->getVehicle()->setSteer(lastSteer); if (IS_PRESSED(HANDBRAKE)) { //dprintf(MY_DEBUG_NOTE, "brake pressed\n"); Player::getInstance()->getVehicle()->setHandbrake(1.0f); } else { Player::getInstance()->getVehicle()->setHandbrake(0); } if (Settings::getInstance()->manualGearShifting) { if (Settings::getInstance()->sequentialGearShifting) { if (IS_PRESSED(GEAR_UP) && getPressed(GEAR_UP)) { Player::getInstance()->getVehicle()->incGear(); } if (IS_PRESSED(GEAR_DOWN) && getPressed(GEAR_DOWN)) { Player::getInstance()->getVehicle()->decGear(); } } else { if (IS_PRESSED(GEAR_1)) { Player::getInstance()->getVehicle()->setGear(1); } else if (IS_PRESSED(GEAR_2)) { Player::getInstance()->getVehicle()->setGear(2); } else if (IS_PRESSED(GEAR_3)) { Player::getInstance()->getVehicle()->setGear(3); } else if (IS_PRESSED(GEAR_4)) { Player::getInstance()->getVehicle()->setGear(4); } else if (IS_PRESSED(GEAR_5)) { Player::getInstance()->getVehicle()->setGear(5); } else if (IS_PRESSED(GEAR_6)) { Player::getInstance()->getVehicle()->setGear(6); } else if (IS_PRESSED(GEAR_R)) { Player::getInstance()->getVehicle()->setGear(-1); } else { Player::getInstance()->getVehicle()->setGear(0); } } } } // if (Settings::getInstance()->AIPlayer == false || Settings::getInstance()->editorMode) if (IS_PRESSED(PHYSICS)) { TheGame::getInstance()->setPhysicsOngoing(!TheGame::getInstance()->getPhysicsOngoing()); } /*else { TheGame::getInstance()->setPhysicsOngoing(false); }*/ if (IS_PRESSED(FPS_CAMERA)) { dprintf(MY_DEBUG_NOTE, "switch camera\n"); TheGame::getInstance()->switchCamera(); } if (IS_PRESSED(SWITCH_HUD)) { dprintf(MY_DEBUG_NOTE, "switch hud\n"); Hud::getInstance()->setVisible(!Hud::getInstance()->getVisible()); } if (IS_PRESSED(LOOK_LEFT) && getPressed(LOOK_LEFT)) { Player::getInstance()->lookLeft(true); } else if (getReleased(LOOK_LEFT)) { Player::getInstance()->lookLeft(false); } if (IS_PRESSED(LOOK_RIGHT) && getPressed(LOOK_RIGHT)) { Player::getInstance()->lookRight(true); } else if (getReleased(LOOK_RIGHT)) { Player::getInstance()->lookRight(false); } if (IS_PRESSED(CHANGE_VIEW)) { Player::getInstance()->switchToNextView(); } if (IS_PRESSED(OPEN_EDITOR)) { if (Settings::getInstance()->editorMode) { MenuManager::getInstance()->open(MenuManager::MP_EDITOR); } } if (IS_PRESSED(RESET_VEHICLE)) { Player::getInstance()->resetVehicle(irr::core::vector3df( TheGame::getInstance()->getCamera()->getPosition().X, TheEarth::getInstance()->getHeight(TheGame::getInstance()->getCamera()->getPosition())+2.5f, TheGame::getInstance()->getCamera()->getPosition().Z)); } if (IS_PRESSED(REPAIR_VEHICLE)) { Player::getInstance()->repairVehicle(); } if (IS_PRESSED(SWITCH_INPUT)) { MenuManager::getInstance()->refreshEventReceiver(); MenuPageEditor::menuPageEditor->refreshAction(); } if (IS_PRESSED(INC_FPS_SPEED)) { TheGame::getInstance()->incFPSSpeed(); } if (IS_PRESSED(DEC_FPS_SPEED)) { TheGame::getInstance()->decFPSSpeed(); } //if (Settings::getInstance()->navigationAssistant == false) //{ if (IS_PRESSED(ROADBOOK_NEXT)) { Player::getInstance()->stepItiner(); Hud::getInstance()->updateRoadBook(); } else if (IS_PRESSED(ROADBOOK_PREV)) { Player::getInstance()->stepBackItiner(); Hud::getInstance()->updateRoadBook(); } if (IS_PRESSED(RESET_PARTIAL)) { Player::getInstance()->resetDistance(); } //} if (IS_PRESSED(EXIT_TO_MENU)) { MenuManager::getInstance()->open(MenuManager::MP_INGAME); } #ifdef DETECT_MEM_LEAKS if (IS_PRESSED(PRINT_MEM_LEAKS)) { VLDReportLeaks(); //_CrtDumpMemoryLeaks(); //assert(0); } if (IS_PRESSED(PRINT_MEM_LEAKS_IRR)) { TheGame::getInstance()->getSmgr()->addTerrainSceneNode("fake/path"); //_CrtDumpMemoryLeaks(); //assert(0); } #endif // DETECT_MEM_LEAKS } #endif // 0 or 1 }
void NDInstanceBase::EndStaticsMem() { VLDReportLeaks(); }
//entry point for any windows program int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //void* myP = (void*)(new Packet(1, 5, 5)); //Packet myPack; //short id; //memcpy( &id, myP, sizeof(short)); //Create console AllocConsole(); //std::cout << "Test console!!!"; //start timer TIM->Start(); D3DApp dapp; //gTextureMan = new TextureManager(); //the handle for the window, filled by a function HWND hWnd; //this struct holds info for the window class WNDCLASSEX wc; //clear out the window class for use ZeroMemory(&wc, sizeof(WNDCLASSEX) ); //fill in the struct with the needed information wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) COLOR_WINDOW; wc.lpszClassName = "WindowClass1"; //register the window class RegisterClassEx(&wc); // create the window and use the result as the handle hWnd = CreateWindowEx(NULL, "WindowClass1", // name of the window class "DirectX by Jimmy Roland", // title of the window WS_OVERLAPPEDWINDOW, // window style 300, // x-position of the window 300, // y-position of the window SCREEN_WIDTH, // width of the window SCREEN_HEIGHT, // height of the window NULL, // we have no parent window, NULL NULL, // we aren't using menus, NULL hInstance, // application handle NULL); // used with multiple windows, NULL // display the window on the screen ShowWindow(hWnd, nCmdShow); //start Visual Leak Detector VLDEnable(); //create global for DirectInput pointer gDInput = new DirectInput(hInstance, hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); //set up and initialize Direct3D dapp.InitD3D(hWnd,hInstance, true); dapp.CreateFPSDisplay(); // enter the main loop: gD3DDev = *dapp.GetDevice(); dapp.VertexDeclarations(); // this struct holds Windows event messages MSG msg; // Enter the infinite message loop while(TRUE) { // Check to see if any messages are waiting in the queue while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // translate keystroke messages into the right format TranslateMessage(&msg); // send the message to the WindowProc function DispatchMessage(&msg); } // If the message is WM_QUIT, exit the while loop if(msg.message == WM_QUIT) break; //DirectInput polling gDInput->poll(); //dapp.SetMousePos(hWnd); // Run game code here dapp.Update( (float)TIM->GetTimeElapsed() ); } VLDReportLeaks(); //clean up DirectX and COM dapp.CleanDirect3D(); //delete global delete gDInput; // return this part of the WM_QUIT message to Windows return msg.wParam; }