• (3 Pages)
  • +
  • 1
  • 2
  • 3

C++ Tile Engine from Scratch -- Part 1

#16 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,208
  • Joined: 14-February 08

Posted 02 August 2012 - 04:37 AM

post engine.cpp
Was This Post Helpful? 0
  • +
  • -

#17 Pixelier  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-August 12

Posted 02 August 2012 - 11:49 AM

#include "Engine.h"
#include <SFML\Graphics.hpp>

Engine::Engine()
{

}

Engine::~Engine()
{

}

bool Engine::Init()
{
	window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "RPG");

	if(!window)
		return false;

	return true;
}

void Engine::RenderFrame()
{

}

void Engine::ProcessInput()
{
	sf::Event evt;
	//Loop through all window events
	while(window->PollEvent(evt))
	{
		if(evt.Type == sf::Event::Closed)
			window->Close();
	}
}

void Engine::Update()
{

}

void Engine::MainLoop()
{
	//Loop until our window is closed
	while(window->IsOpened())
	{
		ProcessInput();
		Update();
		RenderFrame();
	}
}

void Engine::Go()
{
	if(!Init())
		throw "Could not initialize Engine";

	MainLoop();
}

Was This Post Helpful? 0
  • +
  • -

#18 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,208
  • Joined: 14-February 08

Posted 06 August 2012 - 04:27 AM

Seems to just be a typo, PollEvent should be pollEvent according to this http://www.sfml-dev....3069858e3b531b7
Was This Post Helpful? 0
  • +
  • -

#19 Pixelier  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-August 12

Posted 08 August 2012 - 12:37 AM

View Poststayscrisp, on 06 August 2012 - 04:27 AM, said:

Seems to just be a typo, PollEvent should be pollEvent according to this http://www.sfml-dev....3069858e3b531b7



thank you! but i still wont work i can u figure out why "while(window->IsOpened())" is not working.? The "IsOpened" is underlined in red.
Was This Post Helpful? 0
  • +
  • -

#20 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,208
  • Joined: 14-February 08

Posted 10 August 2012 - 04:19 AM

what's the error?
Was This Post Helpful? 0
  • +
  • -

#21 SergeantBalthazar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 14-March 12

Posted 10 August 2012 - 10:59 AM

View PostSuicidalCookie, on 20 May 2011 - 03:14 AM, said:

View PostSuicidalCookie, on 20 May 2011 - 03:06 AM, said:

I followed all the steps but
#ifndef
is underlined in red and the error says "the #endif for this directive is missing"

EDIT
I feel sooo stupid im sorry for the stupid question. I figured out what I did wrong.
Could you please inform me what you did wrong? I can't figure it out. (I'm getting the same error)
Was This Post Helpful? 0
  • +
  • -

#22 SergeantBalthazar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 14-March 12

Posted 10 August 2012 - 01:55 PM

I am getting the following errors when I try to build:
 1>------ Build started: Project: Engine Test, Configuration: Debug Win32 ------
1>  main.cpp
1>Engine.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::WindowSettings const &)" (??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUWindowSettings@1@@Z) referenced in function "private: bool __thiscall Engine::Init(void)" (?Init@Engine@@AAE_NXZ)
1>Engine.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (??0VideoMode@sf@@QAE@III@Z) referenced in function "private: bool __thiscall Engine::Init(void)" (?Init@Engine@@AAE_NXZ)
1>Engine.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::Window::Close(void)" (?Close@Window@sf@@QAEXXZ) referenced in function "private: void __thiscall Engine::ProcessInput(void)" (?ProcessInput@Engine@@AAEXXZ)
1>Engine.obj : error LNK2019: unresolved external symbol "public: bool __thiscall sf::Window::GetEvent(class sf::Event &)" (?GetEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function "private: void __thiscall Engine::ProcessInput(void)" (?ProcessInput@Engine@@AAEXXZ)
1>Engine.obj : error LNK2019: unresolved external symbol "public: bool __thiscall sf::Window::IsOpened(void)const " (?IsOpened@Window@sf@@QBE_NXZ) referenced in function "private: void __thiscall Engine::MainLoop(void)" (?MainLoop@Engine@@AAEXXZ)
1>C:\Users\SergeantBalthazar\Desktop\Coding\C++\RPG Engine\Engine Test\Debug\Engine Test.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 





My Engine.h:
#ifndef _ENGINE_H
#define _ENGINE_H

#include <SFML\Graphics.hpp>

class Engine
{
private:
	//SFML Render Window
	sf::RenderWindow* window;
	//Initialises Engin
	bool Init();
	//Main Game Loop
	void MainLoop();
	//Renders 1 Frame
	void RenderFrame();
	//Process User Input
	void ProcessInput();
	//Updates all Engine Internals
	void Update();
public:
	Engine();
	~Engine();
	//Starts Engine
	void Go(); 
};

#endif 



Engine.cpp:
#include "Engine.h"
#include <SFML/Graphics.hpp>

Engine::Engine()
{

}

Engine::~Engine()
{
	
}

bool Engine::Init()
{
	window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "Engine Test");

	if(!window)
		return false;

	return true;
}

void Engine::RenderFrame()
{

}

void Engine::ProcessInput()
{
	sf::Event evt;
	//Loop through all window events
	while(window->GetEvent(evt))
	{
		if(evt.Type == sf::Event::Closed)
			window->Close();
	}
}

void Engine::Update()
{

}

void Engine::MainLoop()
{
	//Loop until our window is closed
	while(window->IsOpened())
	{
		ProcessInput();
		Update();
		RenderFrame();
	}
}

void Engine::Go()
{
	if(!Init())
		throw "Could Not Initialise Engine";

	MainLoop();
} 


and main.cpp:
#include <Windows.h>

#include "Engine.h"

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
	Engine* engine = new Engine();

	try
	{
		engine->Go();
	}
	catch(char* e)
	{
		MessageBoxA(NULL, e, "Exception Occured", MB_OK | MB_IConerror);
	}
} 



Note: I know it says
 while(window->GetEvent(evt)) 
instead of
 while(window->PollEvent(evt)) 
, but according to Visual C++ Express, PollEvent (or pollEvent) doesn't exist anymore.

View PostSergeantBalthazar, on 10 August 2012 - 01:53 PM, said:

I am getting the following errors when I try to build:
 1>------ Build started: Project: Engine Test, Configuration: Debug Win32 ------
1>  main.cpp
1>Engine.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::WindowSettings const &)" (??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUWindowSettings@1@@Z) referenced in function "private: bool __thiscall Engine::Init(void)" (?Init@Engine@@AAE_NXZ)
1>Engine.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (??0VideoMode@sf@@QAE@III@Z) referenced in function "private: bool __thiscall Engine::Init(void)" (?Init@Engine@@AAE_NXZ)
1>Engine.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::Window::Close(void)" (?Close@Window@sf@@QAEXXZ) referenced in function "private: void __thiscall Engine::ProcessInput(void)" (?ProcessInput@Engine@@AAEXXZ)
1>Engine.obj : error LNK2019: unresolved external symbol "public: bool __thiscall sf::Window::GetEvent(class sf::Event &)" (?GetEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function "private: void __thiscall Engine::ProcessInput(void)" (?ProcessInput@Engine@@AAEXXZ)
1>Engine.obj : error LNK2019: unresolved external symbol "public: bool __thiscall sf::Window::IsOpened(void)const " (?IsOpened@Window@sf@@QBE_NXZ) referenced in function "private: void __thiscall Engine::MainLoop(void)" (?MainLoop@Engine@@AAEXXZ)
1>C:\Users\SergeantBalthazar\Desktop\Coding\C++\RPG Engine\Engine Test\Debug\Engine Test.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 





My Engine.h:
#ifndef _ENGINE_H
#define _ENGINE_H

#include <SFML\Graphics.hpp>

class Engine
{
private:
	//SFML Render Window
	sf::RenderWindow* window;
	//Initialises Engin
	bool Init();
	//Main Game Loop
	void MainLoop();
	//Renders 1 Frame
	void RenderFrame();
	//Process User Input
	void ProcessInput();
	//Updates all Engine Internals
	void Update();
public:
	Engine();
	~Engine();
	//Starts Engine
	void Go(); 
};

#endif 



Engine.cpp:
#include "Engine.h"
#include <SFML/Graphics.hpp>

Engine::Engine()
{

}

Engine::~Engine()
{
	
}

bool Engine::Init()
{
	window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "Engine Test");

	if(!window)
		return false;

	return true;
}

void Engine::RenderFrame()
{

}

void Engine::ProcessInput()
{
	sf::Event evt;
	//Loop through all window events
	while(window->GetEvent(evt))
	{
		if(evt.Type == sf::Event::Closed)
			window->Close();
	}
}

void Engine::Update()
{

}

void Engine::MainLoop()
{
	//Loop until our window is closed
	while(window->IsOpened())
	{
		ProcessInput();
		Update();
		RenderFrame();
	}
}

void Engine::Go()
{
	if(!Init())
		throw "Could Not Initialise Engine";

	MainLoop();
} 


and main.cpp:
 #include <Windows.h>

#include "Engine.h"

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
	Engine* engine = new Engine();

	try
	{
		engine->Go();
	}
	catch(char* e)
	{
		MessageBoxA(NULL, e, "Exception Occured", MB_OK | MB_IConerror);
	}
} 



Note: I know it says
 while(window->GetEvent(evt)) 
instead of
 while(window->PollEvent(evt)) 
, but according to Visual C++ Express, PollEvent (or pollEvent) doesn't exist anymore.

Fixed so it's easier to read
Was This Post Helpful? 0
  • +
  • -

#23 SergeantBalthazar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 14-March 12

Posted 10 August 2012 - 02:51 PM

Also note that I am using SFML 2.0
Was This Post Helpful? 0
  • +
  • -

#24 SergeantBalthazar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 14-March 12

Posted 10 August 2012 - 04:14 PM

Ok I fixed it.
Was This Post Helpful? 0
  • +
  • -

#25 KevinProggerEngine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-August 12

Posted 27 August 2012 - 05:23 AM

View PostSergeantBalthazar, on 10 August 2012 - 04:14 PM, said:

Ok I fixed it.

Could you tell me how you fixed it because im getting errors at

if(evt.Type == sf::Event::Closed)
			window->Close();


Type and Close are underlined in red, and at

while(window->IsOpened())
	{
		ProcessInput();
		Update();
		RenderFrame();
	}  
        


IsOpened is underlined in red , too.
Sorry for bad english :D
Was This Post Helpful? 0
  • +
  • -

#26 KevinProggerEngine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-August 12

Posted 27 August 2012 - 05:33 AM

View PostKevinProggerEngine, on 27 August 2012 - 05:23 AM, said:

View PostSergeantBalthazar, on 10 August 2012 - 04:14 PM, said:

Ok I fixed it.

Could you tell me how you fixed it because im getting errors at

if(evt.Type == sf::Event::Closed)
			window->Close();


Type and Close are underlined in red, and at

while(window->IsOpened())
	{
		ProcessInput();
		Update();
		RenderFrame();
	}  
        


IsOpened is underlined in red , too.
Sorry for bad english :D


So sorry i fixed it like this:
Type must be type, Close must be close and IsOpened must be isOpen!
Was This Post Helpful? 0
  • +
  • -

#27 GunnDawg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-September 12

Posted 03 September 2012 - 05:06 PM

I am getting the error:

error LNK2019: unresolved external symbol _main

I assume this is because so far the code has no main function. How are you guys able to compile and run this without a main function?
Was This Post Helpful? 0
  • +
  • -

#28 GunnDawg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-September 12

Posted 03 September 2012 - 05:31 PM

Sorry I fixed it. I was using a console application instead of a Win32 application.
Was This Post Helpful? 0
  • +
  • -

#29 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Posted 11 September 2012 - 11:22 AM

Hi,

I'm trying to follow this tutorial to get some more inside in how a game engine works.
But I'm getting this error: Error 1 fatal error C1083: Cannot open include file: 'SFML\Graphics.cpp': No such file or directory

I've done the right steps in the Linker though.

Does anybody know what I may have done wrong?

Thanks in advance
Was This Post Helpful? 0
  • +
  • -

#30 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Posted 11 September 2012 - 11:31 AM

View Postfrostraver, on 11 September 2012 - 08:22 PM, said:

Hi,

I'm trying to follow this tutorial to get some more inside in how a game engine works.
But I'm getting this error: Error 1 fatal error C1083: Cannot open include file: 'SFML\Graphics.cpp': No such file or directory

I've done the right steps in the Linker though.

Does anybody know what I may have done wrong?

Thanks in advance


EDIT: changed .cpp to .hpp but it still isn't resolved.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3