Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

130 Neutral

About MicRo

  • Rank
  1. Quote:Are you trying to increase the acceleration everytime the user hits a key? No I'm not trying to increase acceleration, I only increase speed... the ship is moving without acceleration with constant speed (with zero acceleration), but when user pushes the button, he accelerates ship Quote:if you detect a key hit, you set the acceleration to a constant value (e.g. 10, whatever that means). It does not matter if a user holds a key and thus multiple key presses are fired, because the acceleration stays at the same constant value no matter what. If you detect the release of the key, you set the acceleration back to zero. I agree that acceleration stays at the same constant value and it not depends if key is pressed many times, or if it is holded....but the speed changes faster on faster computer.... Imagine: You are holding the button (or constantly pressing)...on faster computer, will be the keypress detected more times than on slower computer...because whole game loop is done faster, the if-clause (in which I'm detecting if the key has been pressed) is tested in shorter intervals too As ursus said, it is necessery to put some timer on button and allow user to press button only if timer is lower/equal 0 than set the timer again etc....
  2. thank you very much, that should work, I'll try it
  3. I'm sorry, but I don't understand why...
  4. Thanks for reply Fred, but I'm sorry, I asked my question badly... ..what you wrote is of cause correct, but as I think, my problem lies in something different: 1.) I have two computers with different CPU speed CPU1 and CPU2, CPU2 is for example 2x faster than CPU1 2.) I want to move with object, in my game it is a spaceship, but I incerase speed with Speed += Acceleration * FrameInterval, only if I push some button 3.) formula x=x0+v0*t+(1/2)*a*t^2 would work great ... if (I pushed button => I increased Speed) => in every step I increase position by calculated Speed 4.) as we know, because CPU2 is faster, moving of the spaceship will be divided to more steps, than on CPU1, so the whole moving will look more smoothly 5.) BUT if I HOLD that accelerate BUTTON, I mentioned, I'll increase the speed on CPU2 faster... for example: void KeyPress() { ... if (Button) { Speed = Speed + (Acceleration * FrameInterval); Button = false; } ... } void Move() { ... X = X + (Speed * FrameInterval) + (Acceleration*0.5 * FrameInterval * FrameInterval); ... } void Loop() { ... KeyPress(); Move(); ... } and my problem is that not only Move() is called more frequently on CPU2, but KeyPress() too :(
  5. Hi, I am solving problem of moving with same speed on different computers with usage of acceleration, and I need a little bit help.... If I use only Speed without acceleration, it is easy, I know that probably the best way how to do that is multiply speed with time, used to redraw scene: X = X + Speed * FrameInterval So for example if Speed=10 and I have CPU1,CPU2 and CPU2 is twice faster than CPU1: time 0: ------- CPU1: X=0, Speed=10 CPU2: X=0, Speed=10 time 0->1: ---------- CPU1: X=0+10*1=10, Speed=10 CPU2: X=0+10*(0.5)=5, Speed=10 X=5+10*(0.5)=10, Speed=10 ----------------------------------------------------------------- Problem shows if I wanna move with acceleration A, I dunno what I am supposed to multiply with FrameInterval... Example if: Speed = Speed + A*FrameInterval X = X + Speed*FrameInterval time 0: ------- CPU1: X=0, Speed=0, A=10 CPU2: X=0, Speed=0, A=10 time 0-1: --------- CPU1: X=0+10*1=10, Speed=0+10*1=10 CPU2: X=0+5*(0.5)=2.5, Speed=0+10*(0.5)=5 X=2.5+5*(0.5)=5, Speed=5 (not accelerated now)* 10 != 5 => This way is bad ----------------------------------------------------------------- Or if only: Speed = Speed + A*FrameInterval X = X + Speed time 0: ------- CPU1: X=0, Speed=0, A=10 CPU2: X=0, Speed=0, A=10 time 0-1: --------- CPU1: X=0+10=10, Speed=0+10*1=10 CPU2: X=0+5=5, Speed=0+10*(0.5)=5 X=5+10=15, Speed=5+10*(0.5)=10 (accelerated now)* 10 != 15 => Bad too ----------------------------------------------------------------- * those (accelerated now) and (not accelerated now) means that, between step 1 a 2 on CPU2 I can press some button to accelerate or not
  6. MicRo

    algorithm of fast exponentiation

    That's exactly, what I wanted, thank you very much sQuid. As you suggested I've used the Russian Peasant algorithm and I've modifed it to polynom exponentation... Everythink works well, but there remains one step in agrawal algorithm, which I have no idea, how to implement... ....Have you any idea how can I find out if given N = a^b ?
  7. Hi, I am really clueless, i am begging you for help with this problem : i wanna know if (x + a)^n is congruent to x^n + a (mod (x^r - 1), n) where numbers a, n, r are given, x is unknown ...and n is VERY HIGH number I know that left and right side are congruent to each other if (x + a)^n mod (x^r - 1) = (x^n + a) mod (x^r - 1) but: a) I don't know what means that ,n in (mod (x^r - 1), n) b) Beacuse n is very high, it would be good to use algorithm of fast exponentiation, but when i was searching on google, i've found only simple examples of fast exponentation...I need to use this method on given POLYNOMS and i don't know how :( Please help...i am working on agrawal algorithm as a school project and I have to refer it next week.... P.S: I've found a link, where same problem was solved, but I didn't undestand it well: https://nrich.maths.org/discus/messages/20805/24083.html?1114255773
  8. i am sorry, you were right the error wasn´t in sdl but in me....i have been using openal in that dll too, but i have forgoten to shutdown openal before exiting the program, so in the same time, when sdl_quit was called i received that error message, now it works correctly...thank you again for helping me Drew
  9. no matter, thank you for helping me... i hope i'll find where the bug is :)
  10. i'm having still same error
  11. ok thanks ...I use devcpp with SDL devpak in that dll i have class engine, which utilize OpenGL/SDL window.... I created win32 dll with these libs included: -mwindows -lSDLmain -lSDL -liberty Libs/GLAUX.LIB Libs/GLU32.LIB Libs/OPENGL32.LIB methods in dll, where i use sdl: //=========================================================================== // CEngine::Run - starts the engine //=========================================================================== bool CEngine::Run(int ScreenWidth, int ScreenHeight, int ScreenDepth) { FrameTime = 0; SWidth = ScreenWidth; SHeight = ScreenHeight; SDepth = ScreenDepth; if (InitSDL() == false) return false; ResizeGLScene(SWidth, SHeight); if (InitOpenGL() == false) return false; // Initialization of main parts of engine EngineFont.BuildFont(); EngineCamera.Create(ScreenWidth, ScreenHeight, MOUSE_NONE); EngineSound.InitOpenAL(); if (OnCreate) OnCreate(); // Run the main loop with pointer to Loop method EngineLoop.Run(Loop); //SDL_Quit(); return true; } //--------------------------------------------------------------------------- //=========================================================================== // CEngine::InitSDL - set the sdl //=========================================================================== bool CEngine::InitSDL() { if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { HC_Engine_ErrorMessage("Unable to initialize SDL: %s\n", SDL_GetError()); return false; } //atexit(SDL_Quit); Screen = SDL_SetVideoMode(SWidth, SHeight, SDepth, SDL_OPENGL | SDL_HWSURFACE | SDL_FULLSCREEN); if (Screen == NULL) { Engine_ErrorMessage("Unable to init video(HW): %s\n", SDL_GetError()); Screen = SDL_SetVideoMode(SWidth, SHeight, SDepth, SDL_OPENGL | SDL_SWSURFACE | SDL_FULLSCREEN); if (Screen == NULL) { Engine_ErrorMessage("Unable to init video(SW): %s\n", SDL_GetError()); return false; } } return true; } //--------------------------------------------------------------------------- //=========================================================================== // CEngine::Loop - loop method //=========================================================================== void CEngine::Loop() { if (OnKeyDown) OnKeyDown(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); EngineCamera.Update(); EngineEnvironment.DrawEnvironment(EngineLoop.GetFrameInterval()); EngineSprite.Update(EngineCamera.GetRealPosition()); EngineCamera.DrawLensFlares(); if (OnDraw) OnDraw(); glFlush(); SDL_GL_SwapBuffers(); if (FreezeCounter < FreezeTime) { FreezeCounter += EngineLoop.GetFrameInterval(); } else { FrameTime += EngineLoop.GetFrameInterval(); } } //--------------------------------------------------------------------------- ...of cause i disabled all that parts of this class, which aren't necessary for running of program, but it haven't solved my problem.... if i use SLD_Quit() application throw exception exactly in place, where ia m calling it - in run method after exiting the main loop....if i disable SDL_Quit error appears later when app is freeing
  12. MicRo

    Open GL in Dev-C++

    Use import MS Visual C++ project (dsp) in devcpp.
  13. MicRo

    Best Compiler for C and C++?

    DevCpp rulez :)
  14. Hi all, I put a part of my code, which contains creation of window an utilization of screen (in SDL) in to a dll file, but problem is that program, which uses this dll crashes in it's end, even that exact code used in this dll worked outside of dll perfectly. I tryed to find where exactly program crashes and I found that it is right after calling SDL_Quit(); So I took a look in to SDL specification and I found a note, that there could be some problems with calling atexit(); and SDL_Quit(); outside dynamic library...but when I removed calling of these functions from my dll, program crashed with same error message (close to the end of the application, I suppose on automatic freeing of sdl). I am completly feckless, I searched this problem on google and other forums, I found some posts with same problem, like this http://twomix.devolution.com/pipermail/sdl/2004-April/061325.html, but no usefull answers :( P.S.: I tryed to call SDL_INIT_NOPARACHUTE in SDL_Init() but it didn´t help.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!