I came back to a project of mine after some time and I quickly remembered why I stopped working on it. I cannot solve this error:
Error LNK1169 one or more multiply defined symbols found
I think I understand what its angry about, but the only way I can solve this issue is to comment out my function definitions in my game.cpp file. I am a little confused on what to do about this error. I think maybe I created the class wrong, but I honestly have no Idea.
EDIT: Changing the code in my main file to include "game.hpp" instead of cpp seems to have fixed the issue. Im going to leave a little time to get some feedback from others, but I will mark the issue as solved later today.
#include "stdafx.h"
#include "Game.hpp"
#include "SplashState.hpp"
namespace TotalControl
{
Game::Game(int width, int height, std::string title)
{
Data->window.create(sf::VideoMode(width, height), title, sf::Style::Close | sf::Style::Titlebar);
Data->stateHand.AddState(StateRef(new SplashState(this->Data)));
this->Run();
}
void Game::Run()
{
//This next bit of code is some important game engine logic. It makes it so frame times are ALWAYS the same. So the game will NOT run
//faster on my computer over yours. It basically will make the game always feel the same. Very important.
float newTime, frameTime, interpolation;
float currentTime = this->Clock.getElapsedTime().asSeconds();
float accumulator = 0.0f;
//Enter the GAME LOOOOOOOOOOOP
while (this->Data->window.isOpen())
{
//Process the state changes that have occured FIRST
this->Data->stateHand.ProcessStateChange();
newTime = this->Clock.getElapsedTime().asSeconds();
frameTime = newTime - currentTime;
if (frameTime > 0.2f)
{
frameTime = 0.2f;
}
currentTime = newTime;
accumulator += frameTime;
while (accumulator >= dt)
{
this->Data->stateHand.GetActiveState()->HandleInput();
this->Data->stateHand.GetActiveState()->Update(dt);
accumulator -= dt;
}
interpolation = accumulator / dt;
this->Data->stateHand.GetActiveState()->Draw(interpolation);
}
}
Game::~Game()
{
}
}
#pragma once
#include <memory>
#include <string>
#include <SFML\Graphics.hpp>
#include "StateHandler.hpp"
#include "AssetsManager.hpp"
#include "InputHandler.hpp"
namespace TotalControl
{
struct GameData
{
StateHandler stateHand;
sf::RenderWindow window;
AssetsManager assets;
InputHandler input;
};
//This is a shared pointer. It basically makes a pointer to each of the things in the GameData Structure. Making it in the namespace, so its
//Globally accesable.
typedef std::shared_ptr<GameData> GameDataRef;
class Game
{
public:
//Initializing our Game with everything needed for the window.
Game(int width, int height, std::string title);
~Game();
private:
//Will be called when the game starts.
void Run();
//This is what we will use across all states to access the managers. This makes is so it's all connected properly.
GameDataRef Data = std::make_shared<GameData>();
//This is for frame independent gameplay.
constfloat dt = 1.0 / 60.0f;
sf::Clock Clock;
};
}
> EDIT: Changing the code in my main file to include "game.hpp" instead of cpp seems to have fixed the issue.
Yeah it would.
Because including .cpp files is almost always the wrong way to do it.
While you were compiling from the command line, and just compiling main.cpp, all would seem to be well.
But as soon as you move to a project based approach, where main.cpp and game.cpp are compiled separately (and then linked), you end up with multiply defined symbols.