udpated SDL_GetTicks() to SDL_GetTicks64()

This commit is contained in:
2022-05-30 14:02:21 -04:00
parent 4aa7fe1692
commit 70402c5382
6 changed files with 53 additions and 23 deletions

View File

@ -21,6 +21,7 @@
// #include "../ui/UIText.h"
#include "../ui/UINineSlice.h"
#include "../cjson/cJSON.h"
#include <cmath>
// tmxparser::TmxMap map;
Manager manager;
@ -185,7 +186,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
uiInfo.addComponent<TransformComponent>(camera.w/gScale-94,10,72*gScale,96*gScale,gScale);
// uiInfo.addComponent<UITextComponent>("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : Bnd1: Bnd2: Bnd3:", 8, 12, gScale);
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : dMvX: diff: bMax:", 8, 12, gScale);
uiInfo.addGroup(groupUI_Layer3);
uiCamXInfo.addComponent<TransformComponent>(camera.w/gScale-48,23,40*gScale,12*gScale,gScale);
@ -233,7 +234,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
//ecs implementation
// player.addComponent<TransformComponent>(860*globalScale,640*globalScale,22,42,globalScale);
player.addComponent<TransformComponent>(150*gScale,100*gScale,22,42,globalScale); // 180,120
player.addComponent<TransformComponent>(150*gScale,100*gScale,22,42,globalScale,3); // 180,120
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
@ -363,9 +364,21 @@ void Game::update()
uiPlayerYInfo.getComponent<UITextComponent>().updateString(std::to_string(playerY));
int * foundBoundaries = predictCollisions();
uiBoundary1Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[0]));
uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[1]));
uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[2]));
int max = foundBoundaries[0];
for (int b=0;b<3;b++){
if (foundBoundaries[b]>max){
max = foundBoundaries[b];
}
}
int desiredMovementX = std::abs(-1*player.getComponent<TransformComponent>().speed*player.getComponent<TransformComponent>().scale);
// int desiredMovementY = player.getComponent<TransformComponent>().velocity.y*player.getComponent<TransformComponent>().speed*player.getComponent<TransformComponent>().scale;
// uiBoundary1Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[0]));
uiBoundary1Info.getComponent<UITextComponent>().updateString(std::to_string((int)desiredMovementX));
// uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[1]));
int difference = player.getComponent<TransformComponent>().position.x-max;
uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)difference));
uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)max));
// uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[2]));
playerPosition.x = playerX;
playerPosition.y = playerY;

View File

@ -19,7 +19,7 @@ int main(int argc, const char * argv[])
const int FPS = 60;
const int frameDelay = 1000 / FPS;
Uint32 frameStart;
Uint64 frameStart;
int frameTime;
// =============================
@ -58,13 +58,13 @@ int main(int argc, const char * argv[])
while (game->running())
{
frameStart = SDL_GetTicks();
frameStart = SDL_GetTicks64();
game->handleEvents();
game->update();
game->render();
frameTime = SDL_GetTicks() - frameStart;
frameTime = SDL_GetTicks64() - frameStart;
if(frameDelay > frameTime)
{