marsong

Members
  • Content count

    29
  • Joined

  • Last visited

Community Reputation

154 Neutral

About marsong

  • Rank
    Member
  1. SDL light effects

    [quote name='PhantomRonin' timestamp='1342809099' post='4961401'] Yea I was thinking of doing this but if I wanted more then one torch I would have trouble [/quote] You could implent a basic lightmap: Setup an array as big as your screen: uint8_t lightmap[SCREEN_SIZE]; - Reset lightmap to 0 (black) - Do one pass and fill this lightmap, you would basically take your lightsources, fill in whites in your lightmap at their position (use some fade out formula so it gets darker further away from the light source) - Alpha blend (multiplicative blend) the screen with your lightmap Although, doing this in software is gonna be pretty slow if you use a high resolution.
  2. Use two input buffers, that way you can keep track of key presses and releases. I use something like this: [code] static char key_state[2][NUM_KEYS]; static int curinput = 0; // this is called every frame void update_input(void) { curinput ^= 1; // flip to next buffer index memset(key_sate[curinput], 0, NUM_KEYS); // clear it // now process all the input events and populate // our key_state buffer, do it in your WndProc, your event loop, // sdl, or whatever // i use sdl, but translate into my own key codes Uint8 *state = SDL_GetKeyboardState(&n); translate_sdlkeys(key_state[curinput], state, n); } // now you can query these two states for key presses and releases like so: // is_key_press: // key is down this frame AND was not down last frame key_state[curinput][key] && !key_state[curinput^1][key]; // is_key_release: // key is up this frame AND was down last frame !key_state[curinput][key] && key_state[curinput^1][key]; // if you just wanna know if the key is up or down, just query the current state key_state[curinput][key] // 1 on down, 0 on up [/code] Obviously wrap that up in functions or your input class, but that is the gist of it.
  3. Best Resolution for 2D games

    [quote name='lonewolff' timestamp='1326401492' post='4902102'] This is fine for a 4:3 ratio screen but if you if you do this on a 16:9 screen, guess what? It gets stretched out. Thats why I go for the users native resoultion. and position things relative (not absolute). From my understanding, this is what the AAA game dev's do. [/quote] But the thing about 2D games is that changing the screen resolution can significantly change the gameplay or feel of the game because of how they usually use planar coordinates. Diablo 2 widescreen "hack" is a good example of this, the oringinal game has quite a narrow view to limit your visibility for monsters, but using the widescreen hack you gain a huge view of the surrounding area and get quite a different experience of the game. In 3D games this effect isn't felt that much because most of the action takes place along the z-axis ("dow/ninto" the monitor)
  4. Help with a timer problem?

    Just store the last time the cursor moved, and if the current time minus the last time is greater than some threshold then move again. [code] struct cursor { float x, y; int last_tick; }; cursor c; cur_tick = get_current_time_in_ms(); if (key up pressed && key is repeated) { // can't remember how you check this in SDL, think there's some flag or something in the keyevent that tells you if it's a repeated key (key being held down) if ((cur_tick - c.last_tick) >= 1000) { // if you hold down the up key, the cursor will take 1 second (1000 ms) to move to the next stop move cursor up; c.last_tick = cur_tick; // update the time it last moved } } else if (key up pressed && not repeated) { // just move without checking time, but still update last_tick move cursor up; c.last_tick = cur_tick; } [/code]
  5. High Resolution Timers

    Quote:Original post by mind_wipe I though that tv.tv_nsec records nano time so doesn't that mean you have to divide by 1000 to get milliseconds? No, you have to divide by a million. Also, you're not using the tv_sec field, you should do this: tv.tv_sec*1000 + tv.tv_nsec/1000000 to get milliseconds. Your other function should just be: return G_GetTime() - st_time; if you want it to return the difference from now to when you called G_SetState.
  6. Quote:Original post by mhagain Have a look here: http://www.gamedev.net/community/forums/topic.asp?topic_id=339475 Apparently SDL_GetTicks is a no-go area on Windows. Might be better off #ifdef'ing it out and using timeGetTime instead (don't forget to use timeBeginPeriod (1) first). SDL_GetTicks uses timeGetTime on Windows, and it sets timeBeginPeriod to 1 (although it depends on how you compile SDL, it has a USE_GETTICKCOUNT macro definition it checks for).
  7. Question about QueryPerformanceCounter

    LARGE_INTEGER is a 64bit integer, there's no chance it will overflow from running too long, it will take years to overflow. [Edited by - marsong on August 10, 2010 1:26:49 PM]
  8. Quote:Original post by gretty Thanks for the replies guys :D Thats sounds reassuring, I'm going to get windows 7 64bit. @twf; Why dont some of those win32 programs work on an 64bit OS? It doesn't have anything to do with using the win32 GDI objects I hope, or do they use some obselete win32 functions or something? I doubt there are "a lot of games" that don't run under 64bit, they would have to be using some draconian DRM that requires some device driver/code injection/etc that isn't available for 64bit versions, or they are actually old 16bit programs (so not actually 32bit) which don't run under 64bit because it dropped support for it.
  9. sscanf problem

    From the sscanf reference: Non-whitespace character, except percentage signs (%): Any character that is not either a whitespace character (blank, newline or tab) or part of a format specifier (which begin with a % character) causes the function to read the next character from str, compare it to this non-whitespace character and if it matches, it is discarded and the function continues with the next character of format and str. If the character does not match, the function fails and returns. So it doesn't quite work like you want it to. It will read the first quote, discard it, continue reading the %s and that will continue until it finds a whitespace, so it will go ahead and include the ending quote in the string (a is now test"), then the position is at the whitespace in the format string, so it will compare your second quote with whitespace, see that they don't match and fail (not null terminating a or b). You're gonna have to write some custom string matching function or use some regexp library.
  10. Inline assembly is generally a bad idea because it can mess with the optimizer, you should either write the entire routine in assembly, or use compiler intrinsics. In this case since it's a class, you should probably go with the compiler intrinsic, because if you want the class methods inlined you would have to write the entire class in assembly (because I don't think msvc can inline functions in object files that has been generated separately by an assembler).
  11. 'Run as an Administrator '

    Quote:Original post by Washu That's a bad idea, mainly because localization will completely break that. The proper way to do it would be to use SHGetFolderPath (SHGetKnownFolderPath on vista, but SHGetFolderPath wraps that) and specify CSIDL_APPDATA for the path you wish to request. You can use CSIDL_COMMON_APPDATA for data that the application requires that is non-user specific. CSIDL_LOCAL_APPDATA is the best one to use though if your application might be run on roaming clients and your data does not need to roam (otherwise the data bloats the roaming profile). %APPDATA% does not break localization, it returns the correct path to C:\Users\<username>\AppData\Roaming (for Vista/7, or whatever the localized path is on Windows XP). You might be thinking about using %USERPROFILE% and appending Application Data (or similar), which would break localization.
  12. 'Run as an Administrator '

    getenv("APPDATA") gives you the path to a directory where user-run programs can read/write to files. You should create a directory in APPDATA (probably the program's name), then you use APPDATA/name to store all files the program needs to write to.
  13. malloc vs api heapalloc

    I thought malloc was suppose to be an efficient allocation mechanism on top of HeapAlloc, but looking at the crt source code you can see that malloc (and operator new) pretty much just calls HeapAlloc directly, so from a logic standpoint they are effectively the same. (Maybe HeapAlloc already is an optimized memory allocator?)
  14. Express Edition C++ 2010 64-bit

    Setting up the x64 compiler as a custom build tool always works, but that is hardly any better then using the command line. You edit the default property sheet, set up the command line and save it, then you right click on the source files, choose to use custom build tool, and then you can build from the IDE as usual. But you wont get any debug/release options, you would have to manually edit the options for each if you need any extra beside the default options you set in the property sheet.
  15. [C++] Cyclic dependency

    It's perfectly safe and the preferred way of doing things. <iosfwd> for example forward declares iostreams and the like, so you don't have to include the beast <iostream> if all you wanted was to add support for the << stream operator.