noodlyappendage

Members
  • Content count

    17
  • Joined

  • Last visited

Community Reputation

130 Neutral

About noodlyappendage

  • Rank
    Member
  1. 2D Platformer Jumping Problems

    I am having a little trouble getting the jumping physics right in a 2D platformer I'm working on. What I'm trying to do is set an impulse value, and then let the gravity force slow it down, and eventually reverse it, but it isn't quite working. The result I'm seeing is the player instantly appears at the peak of the jump, and then begins to fall. I'm sure I'm doing something wrong but I'm not seeing it. My update step looks like this: update(double time) { ddx_ = (forceX_ / mass_) * time; ddy_ = (forceY_ / mass_) * time; impulseX_ *= time; impulseY_ *= time; dx_ += (ddx_ + impulseX_); dy_ += (ddy_ + impulseY_); dx_ += (dx_ * linearDampX_); dy_ += (dy_ * linearDampY_); dx_ *= time; dy_ *= time; x_ += dx_; y_ += dy_; // Impulse should only be set in one update step. impulseX_ = 0.0; impulseY_ = 0.0; }
  2.   I had never heard of these before, and decided to google it to learn more. I stumbled upon this link, http://blogs.msdn.com/b/oldnewthing/archive/2007/11/06/5924058.aspx, which is saying that when using VirtualLock, it is still possible for memory to be paged out by the operating system. It is a few years old though, so is this information still accurate?    Edit: Actually, I just noticed at the bottom, the author includes a follow up which says his interpretation was incorrect, and VirtualLock is sufficient to secure memory. However I still found it to be an interesting read anyway.
  3. I was just wondering what, if any, negative effect the following scenario would have. I create an object instance using the new operator. This object then exists for the life of the entire process. Then, when exiting the application, I do not call a corresponding delete to deallocate. I understand the problem with memory leaks in terms of memory usage of the process at run time, but if the application is exiting, wouldn't the operating system free up any memory it had used anyway?
  4. FMOD Error When Playing Sound

      I was deleting the buffer right after loading the audio. I changed it to store the buffer in my AudioPlayer class instead and it's working now! Thanks!   Still not sure why every other sound worked just fine as those buffers were deleted too, not to mention that this sound would play correctly the first time, but it's working now so I guess I won't dwell on it.
  5.   Thank you! This works exactly how I need it to!
  6. I want to be able to search a private vector, without exposing the vector to the caller, using a custom comparator function that is passed in as a parameter. This seems like it should be possible, since I'm basically just creating a wrapper around a function that already exists, but I'm having trouble. Could this work or is my approach flawed?   What I'm trying to do is something like this: class Container { public: int findObject(Comparator compare); private: std::vector<Object*> objectList_; }; int Container::findObject(Comparator compare) { std::vector<int>::iterator itr; itr = std::find_if(objectList_.begin(); objectList_.end(); compare) { // ... } } I think what I'm not getting is what the Comparator parameter type should be. If I type it as a class, then I don't think I can pass in any arbitrary comparitor I want. It would have to be the same one all the time right?
  7. FMOD Error When Playing Sound

    When trying to play a sound via FMOD, I am getting the following error:   FMOD_ERR_FILE_COULDNOTSEEK "Couldn't perform seek operation. This is a limitation of the medium (ie netstreams) or the file format."     A few strange things about this:   This only happens when I load the sound from memory. When I load it from the file directly, it works fine. I verified that the memory buffer contains the same data as the file, by writing the byte array to a file and comparing the two with a show difference tool. It is an ogg file, just like all the rest of the sounds I am using. This is the only one that has this problem though. It works fine the first time the sound is played. Any subsequent attempt to play the sound generates this error.     I'm pretty new to FMOD, and I'm not finding much about this with google, so I'm pretty lost here... Any assistance would be greatly appreciated.     Here is the code I am using to load the sound from memory: int CFMODAudioPlayer::loadAudioFile(std::string audioname, char* buffer, int bufferSize) { FMOD::Sound* audioStream; FMOD_CREATESOUNDEXINFO audioInfo; memset(&audioInfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); audioInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); audioInfo.length = static_cast<unsigned int>(bufferSize); system_->setStreamBufferSize(65536, FMOD_TIMEUNIT_RAWBYTES); FMODErrorCheck(system_->createStream(static_cast<const char*>(buffer), FMOD_OPENMEMORY, &audioInfo, &audioStream)); int id = sounds_.size(); audioNameIDMap_[audioname] = id; sounds_.push_back(audioStream); channels_.push_back(NULL); return id; }   And here is the code I am using to play the sound: void CFMODAudioPlayer::playAudio(std::string audioname) { int index = audioNameIDMap_[audioname]; FMOD::Channel* channel; FMODErrorCheck(system_->playSound(FMOD_CHANNEL_FREE, sounds_[index], false, &channel)); channels_[index] = channel; }
  8. 2D Platformer Jumping Problems

    [quote name='alvaro' timestamp='1334126097' post='4930146'] Yes, the balance thing. The terminal velocity of a human body is about 56m/s according to Wikipedia. If you want realism, you can set your drag to match that. However, drag is primarily quadratic in the speed of the object, not linear. Or you could ignore physical reality and do whatever feels right in your game, perhaps including a hard speed limit for falling characters. You need to experiment until you get the feeling you want. [/quote] Thank you so much for the help! I came up with a solution I'm happy with. I took some time to play the games that are an influence on what I'm trying to make and I realized the player characters actually don't even really use acceleration when they move, just a constant velocity. I think if I were to write a platformer where you can't change direction in an instant it would be frustrating so what I did was add a movement vector that sets a constant velocity and in my update function I added them like so: [CODE] x_ += (time * (dx_ + movementX_)); y_ += (time * (dy_ + movementY_)); [/CODE] So I can still apply external forces like gravity, or a gust of wind, or standing on a conveyor belt or someting, but also have the option to move with a constant velocity as well. In case anyone's interested here's a compiled version with my changes: [url="http://www.mediafire.com/?14lk6gaplgu69zi"]http://www.mediafire...14lk6gaplgu69zi[/url]. There's still a few bugs to work out but I think the biggest hump has been passed. Thanks again!
  9. 2D Platformer Jumping Problems

    [quote name='alvaro' timestamp='1334110945' post='4930085'] Well, what you had there was some for of air resistance, but perhaps it was too much, so it felt like jumping in molasses. If your character is sliding on the floor, you need to implement friction. [/quote] Ah, I see. But then doesn't the problem exist that given enough time in the air, with such a low linearDamp value, the player would be able to get to very high velocities? Or maybe I should just keep playing around with it to see if I can find a good balance.
  10. 2D Platformer Jumping Problems

    [quote name='alvaro' timestamp='1334109296' post='4930076'] [quote][code] dx_ += ddx_; dy_ += ddy_; [/code][/quote] Do you mean this? [code] dx_ += time*ddx_; dy_ += time*ddy_;[/code] It looks like your linear damp might be too large. If you set it to zero, your jump should be completely symmetric. [/quote] You're right, I set it to 0.0001 and it felt much better jumping, and I also scaled the acceleration by time. But When I set it too low things move too fast and get slippery. Or maybe this is just because I need to implment friction/air resistance?
  11. 2D Platformer Jumping Problems

    In the 2D platformer I'm working on, the jumping feels bad and I'm not sure if my variables are set poorly, or if the design I'm using is a bad choice. When I jump, the player jumps up very quickly, and then falls at a slower rate. Ideally I'd want the jump and fall to feel like they're the same speed. Currently, to jump I'm applying an impulse, and then letting gravity take over. To slow the jump speed down I tried increasing the gravity but then the falling speed doesn't feel good. When I try to lower the magnitude of the impulse, I can't get the desired jump height. It seems like every time I try tweaking one variable to fix a problem it produces some other undesirable result. I guess what I want is to maintain the current jump height, but also have the jumping speed be slowed so that it's equal to the falling speed (gravity). Am I taking entirely the wrong approach here? If you want to see what I'm talking about you can download the "game" here: [url="http://www.mediafire.com/?jfn3jdxvc5nvspq"]http://www.mediafire...jfn3jdxvc5nvspq[/url], enter is start, arrows move, x is jump Here is the code to calculate position: [CODE] void CPhysicsController::update(double time) { ddx_ = forceX_ / mass_; ddy_ = forceY_ / mass_; dx_ += ddx_; dy_ += ddy_; float linearDamp = -0.15f; dx_ += (dx_ * linearDamp); dy_ += (dy_ * linearDamp); x_ += (time * dx_); y_ += (time * dy_); } void CPhysicsController::applyForce(float forceX, float forceY) { forceX_ += forceX; forceY_ += forceY; } void CPhysicsController::applyImpulse(float impulseX, float impulseY) { dx_ += impulseX; dy_ += impulseY; } [/CODE] For gravity I do this: [CODE] if (physicsControllers_[i]->isOnGround() == false) { physicsControllers_[i]->applyForce(0.0f, 70.0f); } [/CODE] And for jumping, I do this: [CODE] if (physicsController_->isOnGround() == true) { physicsController_->applyImpulse(0.0f, -2000.0f); } [/CODE]
  12. Can I use events in C++ like in C#?

    [quote name='fastcall22' timestamp='1331615475' post='4921578'] [quote name='noodlyappendage' timestamp='1331615266' post='4921576'] Whoops, you're right I am in release mode. I switched to debug and I get an access violation in one of the boost header files when it tries to connect the signal though. [/quote] Check the call stack and inspect the variables in your program -- make sure you're hooking everything up correctly. [/quote] Hmm. It even happens in the basic Hello World example from the boost tutorial. I wonder if maybe it's some setting in the IDE? I'll keep investigating... Edit: Looks like it is this [url="http://stackoverflow.com/questions/137089/boostsignal-memory-access-error"]http://stackoverflow.com/questions/137089/boostsignal-memory-access-error[/url]
  13. Can I use events in C++ like in C#?

    [quote name='Washu' timestamp='1331614528' post='4921575'] You are likely trying to debug in release mode. Which will often inline functions where possible. [/quote] Whoops, you're right I am in release mode. I switched to debug and I get an access violation in one of the boost header files when it tries to connect the signal though.
  14. Can I use events in C++ like in C#?

    [quote name='alvaro' timestamp='1331606878' post='4921551'] "A list of callbacks" is also called "a signal", and there are several signal libraries for C++ around. I've used Boost.Signals before and it's nice and easy, although I've heard criticisms about its performance (which didn't matter much in the situations where I've used them). [/quote] Thanks, I downloaded boost and got some wonky code working with signals. I'm sure I did it wrong because it won't let me put break points in the method it calls, but apparently it is running the code! So good enough for now at least.
  15. I have a game object manager class that manages a list of all the game objects. I also have a physics manager class that stores the collision geometry for each object. When the physics manager does collision detection, I'd like for it to raise an event to the main application class with the ID's of the two objects colliding, so I can get them from the game object manager and call their CollisionResponse functions. In C# I know how I would do this, but I'm using C++ and having some trouble. Is this even possible, or am I taking the wrong approach?