Basically, I crashed my computer when I ran my code.
My friend told me the reason was probably due to something about overheating my comp somehow.
Later on I ran this code on my laptop and when I opened my task manager my CPU Usage was at 100%.
So I know I'm doing something horrifically wrong, but I don't know what.
Originally the code was all in the main function and it worked fine, but only when
I rewrote the code in the game class did the program became problematic. Please help
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <cctype>
class Game
{
private:
sf::RenderWindow m_window;
sf::Vector2u m_windowSize;
sf::View m_mainView;
sf::Event m_event;
sf::Clock m_clock;
sf::CircleShape m_Player;
public:
Game();
void run();
private:
void getImput();
void updateLogic();
void renderGraphics();
};
Game::Game()
:m_windowSize(1024, 640)
,m_window(sf::VideoMode(m_windowSize.x, m_windowSize.y), "Title")
{
m_window.setFramerateLimit(100);
m_Player.setRadius(40.f);
m_Player.setPosition(30.f, 30.f);
m_Player.setFillColor(sf::Color::Cyan);
}
void Game::run(){
while(m_window.isOpen()){
getImput();
sf::sleep(sf::milliseconds(5));
updateLogic();
renderGraphics();
}
}
void Game::getImput(){
while(m_window.pollEvent(m_event)){
switch (m_event.type){
case sf::Event::Closed:
m_window.close();
break;
case sf::Event::KeyPressed:
if(m_event.key.code == sf::Keyboard::F4){
//Resize Window
m_windowSize.x = 800;
m_windowSize.y = 600;
// Apply possible size changes
m_window.setSize(sf::Vector2u(m_windowSize.x, m_windowSize.y));
m_mainView = sf::View(sf::FloatRect(0.f, 0.f, m_windowSize.x, m_windowSize.y));
m_window.setView(m_mainView);
}
break;
default:
//idk
break;
}
}
}
void Game::updateLogic(){
//Update the Logic here
}
void Game::renderGraphics(){
m_window.clear();
m_window.draw(m_Player);
m_window.display();
}
int main()
{
//Game
Game game;
game.run();
return 0;
}