Ah ok. I got it. One last question (assuming everything else looks good) Since SDL_BlitSurface takes SDL_Surface* as a parameter, I need to use mySharedPtr.get() to get a raw pointer to pass into the parameter right?
- Viewing Profile: Posts: SonicD007
Community Stats
- Group Members
- Active Posts 298
- Profile Views 2,513
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
Posts I've Made
In Topic: Smart Pointers and Resource Management (SDL)
11 March 2013 - 10:06 AM
In Topic: Smart Pointers and Resource Management (SDL)
11 March 2013 - 09:00 AM
Not quite sure how to do this exactly
std::shared_ptr<SDL_Surface> foo(SDL_LoadBMP(filePath.c_str()), SDL_FreeSurface(foo));
That's what I have so far but since foo is being declared here, foo is undefined in the second parameter. I was thinking of doing something like
SDL_Surface* temp = SDL_LoadBMP(filePath.c_str());
std::shared_ptr<SDL_Surface> foo(*temp, SDL_FreeSurface(temp));
but I'm not sure if this would be a correct use of shared_ptr nor can I compile that because it says
4 IntelliSense: no instance of constructor "std::tr1::shared_ptr<_Ty>::shared_ptr [with _Ty=SDL_Surface]" matches the argument list c:\users\sonicd007\documents\visual studio 2010\projects\prototypes\resource management\resourcecontroller.cpp 17
In Topic: Fixed Time Step Game loop (again..)
25 February 2013 - 12:16 PM
Thank you for the help. Everything looks good now. I know I'm missing the frame cap so I need to add that but does everything else look correct now with the updates?
#include <SDL.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
cout << "Error starting SDL" << endl;
bool quit = false;
const uint64_t UPDATES_PER_SECOND = 33;
const uint64_t MILLISECONDS_PER_UPDATE = 1000/UPDATES_PER_SECOND;
int positionX = 0;
uint64_t currentTime = 0;
uint64_t lastUpdate = 0;
uint64_t nextUpdate = 0;
int interpolationPercent = 0;
lastUpdate = SDL_GetTicks();
while (!quit)
{
currentTime = SDL_GetTicks();
while (currentTime - nextUpdate > MILLISECONDS_PER_UPDATE)
{
//Do update
positionX += 2;
nextUpdate += MILLISECONDS_PER_UPDATE;
cout << "CurrentTime: " << currentTime << endl;
cout << "NextUpdate: " << nextUpdate << endl;
cout << "AfterUpdate: " << positionX << endl;
lastUpdate = currentTime;
}
interpolationPercent = ((currentTime - lastUpdate) * 100) / MILLISECONDS_PER_UPDATE;
cout << "Interpolation Percent: " << interpolationPercent << endl;
}
SDL_Quit();
return 0;
};
CurrentTime: 1651 NextUpdate: 1650 AfterUpdate: 110 Interpolation Percent: 0 Interpolation Percent: 6 Interpolation Percent: 10 Interpolation Percent: 13 Interpolation Percent: 16 Interpolation Percent: 20 Interpolation Percent: 20 Interpolation Percent: 23 Interpolation Percent: 26 Interpolation Percent: 30 Interpolation Percent: 33 Interpolation Percent: 36 Interpolation Percent: 40 Interpolation Percent: 43 Interpolation Percent: 46 Interpolation Percent: 46 Interpolation Percent: 50 Interpolation Percent: 53 Interpolation Percent: 56 Interpolation Percent: 60 Interpolation Percent: 63 Interpolation Percent: 66 Interpolation Percent: 70 Interpolation Percent: 73 Interpolation Percent: 76 Interpolation Percent: 80 Interpolation Percent: 83 Interpolation Percent: 86 Interpolation Percent: 90 Interpolation Percent: 93 Interpolation Percent: 96 Interpolation Percent: 96 CurrentTime: 1681 NextUpdate: 1680 AfterUpdate: 112 Interpolation Percent: 0 Interpolation Percent: 10 Interpolation Percent: 13 Interpolation Percent: 13 Interpolation Percent: 16 Interpolation Percent: 20 Interpolation Percent: 23 Interpolation Percent: 26 Interpolation Percent: 30 Interpolation Percent: 33 Interpolation Percent: 33 Interpolation Percent: 36 Interpolation Percent: 40 Interpolation Percent: 43 Interpolation Percent: 46 Interpolation Percent: 50 Interpolation Percent: 53 Interpolation Percent: 56 Interpolation Percent: 56 Interpolation Percent: 60 Interpolation Percent: 63 Interpolation Percent: 66 Interpolation Percent: 70 Interpolation Percent: 73 Interpolation Percent: 73 Interpolation Percent: 76 Interpolation Percent: 80 Interpolation Percent: 83 Interpolation Percent: 86 Interpolation Percent: 90 Interpolation Percent: 90 Interpolation Percent: 93 Interpolation Percent: 96 CurrentTime: 1711 NextUpdate: 1710 AfterUpdate: 114
In Topic: Fixed Time Step Game loop (again..)
25 February 2013 - 11:14 AM
Thanks. It still doesn't look correct though. Here is a sample output:
CurrentTime: 109 NextUpdate: 33 AfterUpdate: 2 CurrentTime: 109 NextUpdate: 66 AfterUpdate: 4 CurrentTime: 109 NextUpdate: 99 AfterUpdate: 6 Interpolation Percent: 330 Interpolation Percent: 36 Interpolation Percent: 6 Interpolation Percent: 3 Interpolation Percent: 6 Interpolation Percent: 3 Interpolation Percent: 6 Interpolation Percent: 3 Interpolation Percent: 6 CurrentTime: 133 NextUpdate: 132 AfterUpdate: 8 Interpolation Percent: 3 Interpolation Percent: 15 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 9 CurrentTime: 166 NextUpdate: 165 AfterUpdate: 10 Interpolation Percent: 9 Interpolation Percent: 27 Interpolation Percent: 6 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 CurrentTime: 200 NextUpdate: 198 AfterUpdate: 12 Interpolation Percent: 9 Interpolation Percent: 18 Interpolation Percent: 6 Interpolation Percent: 9 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 Interpolation Percent: 6 CurrentTime: 232 NextUpdate: 231 AfterUpdate: 14 Interpolation Percent: 9 Interpolation Percent: 33 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 12 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 12 CurrentTime: 266 NextUpdate: 264 AfterUpdate: 16 Interpolation Percent: 9 Interpolation Percent: 30 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 12 Interpolation Percent: 9 CurrentTime: 298 NextUpdate: 297 AfterUpdate: 18 Interpolation Percent: 9 Interpolation Percent: 30 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 9 Interpolation Percent: 12 Interpolation Percent: 9 Interpolation Percent: 12
EDIT: seems like there's a bug with the [/code]. Doesn't show my text after it when I post the first time. Anyway...
Those numbers don't look right. First off, why did interpolate percentage reach 330? It should never reach > 100 no? It's also increasing, then decreasing before an update even occurred. I must be doing something wrong :/
In Topic: Fixed Time Step Game loop
10 February 2013 - 06:14 PM
Thank you so much everyone! L. Spiro, thank you for clearing things up for me, that's two blogs you've made that've helped me out so far ![]()
- Home
- » Viewing Profile: Posts: SonicD007

Find content