This commit is contained in:
Julian Nießner
2018-05-01 15:19:29 +02:00
parent 515fe8a109
commit e0ce5983e8
45 changed files with 1236 additions and 582 deletions

View File

@@ -1,90 +0,0 @@
#include <iostream>
#include "DarkRP2D.h"
#include "utility/Utility.h"
#include "entities/components/Position.h"
#include "entities/MovementSystem.h"
#include "entities/RenderSystem.h"
#include "entities/DestructSystem.h"
void DarkRP2D::create(SDL_Renderer *gRenderer, InputHandler *inputHandler) {
this->gRenderer = gRenderer;
this->inputHandler = inputHandler;
//Load PNG texture
gTexture = utility::loadTexture( "assets/police_officer.png", gRenderer);
ex = new entityx::EntityX();
ex->systems.add<DestructSystem>();
ex->systems.add<MovementSystem>();
ex->systems.add<RenderSystem>();
ex->systems.configure();
entityx::Entity entity = ex->entities.create();
entity.assign<Position>();
entity.destroy();
}
unsigned int ups = 0;
unsigned int fps = 0;
unsigned int acc = 0;
void DarkRP2D::loop(unsigned int deltaTime) {
accumulator += deltaTime;
acc += deltaTime;
Command *command = inputHandler->handleInput();
if (command) {
command->execute();
}
skippedFrames = 0;
while (accumulator >= MS_PER_UPDATE && skippedFrames <= MAX_FRAMESKIP) {
accumulator -= MS_PER_UPDATE;
update(MS_PER_UPDATE/1000.0f); //Converted to Sec for normalization
ups++;
skippedFrames++;
}
if(acc >= 1000) {
std::cout << "Updates per second: " << ups << " Frames per Second: " << fps << std::endl;
acc -= 1000;
ups = 0;
fps = 0;
}
fps++;
render(MS_PER_UPDATE/1000.0f);
}
void DarkRP2D::update(double deltaInSec) {
ex->systems.update<DestructSystem>(deltaInSec);
ex->systems.update<MovementSystem>(deltaInSec);
}
void DarkRP2D::render(double deltaInSec) {
//Clear screen
SDL_RenderClear( gRenderer );
ex->systems.update<RenderSystem>(deltaInSec);
SDL_Rect textureRect; //create a rect
textureRect.x = 0; //controls the rect's x coordinate
textureRect.y = 0; // controls the rect's y coordinte
textureRect.w = 64; // controls the width of the rect
textureRect.h = 64; // controls the height of the rect
//Render texture to screen
SDL_RenderCopy( gRenderer, gTexture, NULL, &textureRect );
//Update screen
SDL_RenderPresent( gRenderer );
}
void DarkRP2D::resize(int width, int height) {
}
DarkRP2D::~DarkRP2D() {
//Free loaded image
SDL_DestroyTexture( gTexture );
delete ex;
gTexture = NULL;
}