darkelf2k5

Members
  • Content count

    321
  • Joined

  • Last visited

Community Reputation

286 Neutral

About darkelf2k5

  • Rank
    Member
  1. objectList.erase( std::remove_if( objectList.begin(), objectList.end(), [](Trap*& ptr) -> bool { if (ptr->CheckBounds()) { delete ptr; return true; } return false; } ), objectList.end() ); One possible implementation. Use a local functor if you don't have lambdas. BTW, it's not working for you because you increment an iterator that you have just erased. So this should work too: for (typename list<T*>::iterator it = objectList.begin(); it != objectList.end(); ) { typename list<T*>::iterator temp = it++; // post increment "it" here, post preview won't show me the double operator if ((*temp )->CheckBounds()) { delete *temp ; objectList.erase(temp ); } } Did no test the last one thou.
  2. C++ File I/O Binary Vs Text

    It should. But of course then you need to format it yourself. If you just dumping done text, it's no problem.
  3. C++ File I/O Binary Vs Text

    I does if you write numbers. Dumping text will take the same space. To use binary I/O you need to create the stream with the binary flag. std::ofstream fout( "out.txt", ios::out | ios::binary ); Then use fout.write(...).
  4. C++ File I/O Binary Vs Text

    For binary I/O, use the read/write member functions. <</>> ops will do text I/O only AFAIK. 123102309: Text mode: 123102309 Binary mode: edVÌ or something similar Writing a 32 bit int in binary should take 4 bytes exactly. Doing it in text mode it takes a byte size od at least the amount of digits needed to represent the number.
  5. a slow 2D array

    Redrawing the whole console is slow. Maybe try updating only the tiles that actually changed? For example, if p needs to go right 1 character, set the * next to p to a p, and p's old position to *. Update only what's changed. With a scrolling map you will still get the flicker thou.
  6. Decompilers

    Look around here: http://www.program-transformation.org/Transform/WebHome IDA Pro from hexrays is a very powerful diassembler that can decompile too. You can take a look at that too.
  7. XInput help.

    Try just adding a #define __in before including the XInput headers. AFAIK __in is a macro hint only, it does nothing.
  8. XInput help.

    __in? Maybe you need windows.h
  9. C_str error

    stringstream can only give you an std::string, so it should be: system(profile.str().c_str());
  10. Looks like the problem is not with the code, but with the linking. Look at the error message. Not familiar with pocket pc but looks like you are building for ARM platform and the "coredll.lib" was built for THUMB. At least that's what I get from the linker error you posted. Try this: In VS go into your project settings > Linker > Advanced There you have a TargetMachine field. Try setting it to THUMB. Or if you want to link for ARM, you'll need an coredll.lib(COREDLL.dll) that was build using ARM for TargetMachine. Hope this helps.
  11. Quote:Original post by toglia I'm not sure about a vector, cause from what I know, vectors are basically dynamic arrays, and every time objects are pushed or popped the array is resized and some memory management might occur to maintain the memory order, making the whole process very very slow for this. std::vector only grows if it needs more space. If it has 1000 elements one frame and 800 the next, nothing should happen allocation-wise. If the capacity is 1000, it will not allocate more unless you happen to push_back the 1001th element.
  12. Express Edition C++ 2010 64-bit

    AFAIK express editions do not support x64 by default. There is a way to work around it, I think, there was a post about it I think here the other day.
  13. 8086 instruction set?

    I stand corrected.
  14. 8086 instruction set?

    x86 is x86. The only thing they keep adding is new SSE instructions. They can't really add any new instruction to the x68 architecture between Core and Core2, it would destroy backwards compatibility. See http://www.sandpile.org/ http://www.agner.org/optimize/ - the manuals on architectures And I second the Intel manuals.
  15. First, check if the code actually enters into the WM_INPUT at all. It's a common mistake to process away all the messages before looking for WM_INPUT, if you do this separately. If it isn't that, check every API function for errors. Mouse coords are almost always relative by default so long mx = raw->data.mouse.lLastX; long my = raw->data.mouse.lLastY; should be // declare somwhere static long mx = 0; static long my = 0; mx += raw->data.mouse.lLastX; my += raw->data.mouse.lLastY; Make sure you check the flag if it's absolute or relative. I'll post my implementation I wrote recently. It works fine for me. ri.h #include <cstdint> static const uint8_t riDownFirst = 1; static const uint8_t riRelease = 2; static const uint8_t riDown = 3; static const uint8_t riDoubleClick = 4; static const uint8_t riScrollUp = 1; static const uint8_t riScrollDown = -1; void riPoll(); uint8_t riKeyState( uint8_t Key ); int32_t riMouseX(); int32_t riMouseY(); int32_t riMouseXBal(); int32_t riMouseYBal(); uint8_t riMouseState( uint8_t Button ); uint8_t riDblClick( uint8_t Button ); int8_t riMouseWheel(); // All Standard Windows key codes included here to avoid the evil windows.h include #define VK_LBUTTON 0x01 #define VK_RBUTTON 0x02 #define VK_CANCEL 0x03 #define VK_MBUTTON 0x04 /* NOT contiguous with L & RBUTTON */ //...omitted for great justice! ri.cpp #define WIN32_LEAN_AND_MEAN #include <Windows.h> #include "ri.h" static BOOL init_done = false; static uint8_t KeyboardState[256] = {0}; static int32_t mxr = 0; static int32_t myr = 0; static POINT Cursor; static uint8_t MouseState0[5] = {0}; static uint8_t MouseState1[5] = {0}; static DWORD MouseTime0[5] = { 0, 0, 0, 0, 0 }; static DWORD MouseTime1[5] = { 1000, 1000, 1000, 1000, 1000 }; static int8_t MWheel = 0; int8_t riMouseWheel() { return MWheel == 0 ? 0 : MWheel < 0 ? riScrollDown : riScrollUp; } void riProcessMouseMessage( const RAWMOUSE* rmouse, DWORD Time ) { GetCursorPos( &Cursor ); if ( MOUSE_MOVE_ABSOLUTE ^ rmouse->usFlags ) { mxr += rmouse->lLastX; myr += rmouse->lLastY; } else { mxr = rmouse->lLastX; myr = rmouse->lLastY; } for ( int i = 0; i < 5; i++ ) { const uint16_t MASK_DOWN = (1<<(2*i)); const uint16_t MASK_UP = MASK_DOWN << 1; MouseState1[i] = MouseState0[i]; if ( MASK_DOWN & rmouse->usButtonFlags ) { MouseState1[i] = 1; MouseTime0[i] = MouseTime1[i]; MouseTime1[i] = Time; } else if ( MASK_UP & rmouse->usButtonFlags ) { MouseState1[i] = 0; } } MWheel = ( RI_MOUSE_WHEEL & rmouse->usButtonFlags ) ? rmouse->usButtonData : 0; } uint8_t riMouseState( uint8_t Button ) { return 0x3 & ((MouseState0[Button-1] << 1) | MouseState1[Button-1]); } uint8_t riDblClick( uint8_t Button ) { if ( (MouseTime1[Button-1] - MouseTime0[Button-1]) < 500 ) { return riDoubleClick; } return 0; } void riProcessKBMessage( const RAWKEYBOARD* rkbd ) { KeyboardState[rkbd->VKey] &= 0xfe; KeyboardState[rkbd->VKey] |= 1 - (RI_KEY_BREAK & rkbd->Flags); } uint8_t riKeyState( uint8_t Key ) { return 0x3 & KeyboardState[Key]; } int32_t riMouseX() { return mxr; } int32_t riMouseY() { return myr; } int32_t riMouseXBal() { return Cursor.x; } int32_t riMouseYBal() { return Cursor.y; } void riPoll() { if ( !init_done ) { RAWINPUTDEVICE Rid[2] = {0}; Rid[0].usUsagePage = 0x01; Rid[0].usUsage = 0x02; Rid[0].dwFlags = RIDEV_DEVNOTIFY;//RIDEV_NOLEGACY; // adds HID mouse and also ignores legacy mouse messages Rid[0].hwndTarget = 0; Rid[1].usUsagePage = 0x01; Rid[1].usUsage = 0x06; Rid[1].dwFlags = 0;//RIDEV_NOLEGACY; // adds HID keyboard and also ignores legacy keyboard messages Rid[1].hwndTarget = 0; if (RegisterRawInputDevices(Rid, 2, sizeof(Rid[0])) == FALSE) { //registration failed. Call GetLastError for the cause of the error return; } init_done = true; return; } //CopyMemory( KeyboardState0, KeyboardState1, sizeof(KeyboardState0) ); for ( int i = 0; i < 256; i++ ) { const uint8_t last = 1 & KeyboardState[i]; KeyboardState[i] = (KeyboardState[i] << 1) | last; } CopyMemory( MouseState0, MouseState1, sizeof(MouseState0) ); MWheel = 0; for ( int i = 0; i < 5; i++ ) { if ( (MouseTime1[i] - MouseTime0[i]) < 500 ) { MouseTime1[i] = 500; MouseTime0[i] = 0; } } MSG msg = {0}; while ( PeekMessage( &msg, 0, WM_INPUT_DEVICE_CHANGE, WM_INPUT, PM_REMOVE | PM_QS_INPUT ) ) { if ( WM_INPUT_DEVICE_CHANGE == msg.message ) { DefWindowProc(msg.hwnd, msg.message, msg.wParam, msg.lParam); } if ( RIM_INPUT == GET_RAWINPUT_CODE_WPARAM( msg.wParam ) ) { UINT dwSize = sizeof(RAWINPUT); RAWINPUT raw = {0}; GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, &raw, &dwSize, sizeof(RAWINPUTHEADER)); if ( RIM_TYPEKEYBOARD == raw.header.dwType ) { riProcessKBMessage( &raw.data.keyboard ); } else if ( RIM_TYPEMOUSE == raw.header.dwType ) { riProcessMouseMessage( &raw.data.mouse, msg.time ); } } DefWindowProc(msg.hwnd, msg.message, msg.wParam, msg.lParam); } } If you do input separately, the message process order will be important. You can lift that constraint by processing all but the raw input messages: MSG msg = {0}; while ( PeekMessage( &msg, 0, 0, WM_INPUT_DEVICE_CHANGE - 1, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } while ( PeekMessage( &msg, 0, WM_INPUT + 1, 0xffffffff, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); }