Converting my game from C to C++

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
fritz

Converting my game from C to C++

Post by fritz »

Hi, I have recently been converting my app so I can use support from classes so I can speed up development... I have carfully converted and did everything right, made decleration for all my cvars and what not and have no errors except this...

Code: Select all

LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Release/GameAlpha.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
I am using MSVC++ 6.0 Standard edition...

And I would *REALLY* appreciate some help, took me about a hour and a half converting all of this fixing the errors and now i just get this... I have also made sure that all my librarys are linked in the project settngs and etc... so if any one is interested in helping me, even if it includes looking at my source for issues, I would GREATLY appreciate it.

Regards,
Zak Farrington
fritz

Post by fritz »

Err guess not a problem compileing, I mean linking... So maybe a problem in my project settings?

heres my project settings:

Code: Select all

/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Release/GameAlpha.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c 
the librarys im linking

Code: Select all

kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 
and resource options

Code: Select all

/l 0x409 /fo"Release/resource.res" /d "NDEBUG" 
Anyways i'm sure one of you Irrlicht gurus can quickly notice what im missing and help a guy like me out :p
fritz

My Source

Post by fritz »

main.cpp

Code: Select all

#include "Game.h"

using namespace irr;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	//ut << "Do you want to run A02?\r\n";

	CGame game;
	game.run();

	return 0;
}
Game.h

Code: Select all

// Game.h: interface for the CGame class.
//
//////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <irrlicht.h>
#include <stdio.h>
#include <iostream.h>

using namespace irr;

#if !defined(AFX_GAME_H__D1AE4533_5894_4406_BA5E_9F86B3060903__INCLUDED_)
#define AFX_GAME_H__D1AE4533_5894_4406_BA5E_9F86B3060903__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CGame : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event);
	void run();
	CGame();
	virtual ~CGame();

private:
	IrrlichtDevice *device;

	video::IVideoDriver* driver;

	scene::ICameraSceneNode* camera;
	scene::ISceneManager* smgr;

	scene::IAnimatedMesh* LevelMesh;
	scene::ISceneNode* LevelNode;

	scene::ISceneNode* skyboxNode;

	gui::IGUIEnvironment* env;

	scene::IMetaTriangleSelector* metaSelector;
	scene::ITriangleSelector* mapSelector;

	scene::IAnimatedMeshSceneNode* ModelNode_1;


};

#endif // !defined(AFX_GAME_H__D1AE4533_5894_4406_BA5E_9F86B3060903__INCLUDED_)
Game.cpp

Code: Select all

// Game.cpp: implementation of the CGame class.
//
//////////////////////////////////////////////////////////////////////

#include "Game.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGame::CGame()
{

}

CGame::~CGame()
{

}

void CGame::run()
{
	device =
		createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600), 16, false, false, this);

	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	//scene::ISceneManager* sm = device->getSceneManager();
	env = device->getGUIEnvironment();
	
	static irr::video::ITexture * loadbar = NULL;
	driver->beginScene(true, false, irr::video::SColor(0,0,0,0)); 

	loadbar =  driver->getTexture("load.tga"); 

	//irr::gui::IGUIFont* font = env->getBuildInFont(); 

	//** DRAW TEXT LOADING MESSAGE

	driver->draw2DImage(loadbar, core::position2d<s32>(0,00),core::rect<s32>(0,0,800,600), 0,video::SColor(255,255,255,255), false); 

	
	
	driver->endScene(); 


//**:~~~~~~~~~~~~~~~~~~~~~~~~~


	device->getFileSystem()->addZipFileArchive("main.dll");
	
	LevelMesh = smgr->getMesh("dapalace.bsp");

	if (LevelMesh)
	{
		LevelNode = smgr->addOctTreeSceneNode(LevelMesh->getMesh(0));
	}


	
	if (LevelNode)
	{		
		LevelNode->setPosition(core::vector3df(0,1120,-860));

		mapSelector = smgr->createOctTreeTriangleSelector(LevelMesh->getMesh(0), LevelNode, 128);
		LevelNode->setTriangleSelector(mapSelector);
		mapSelector->drop();

		//** Set up skybox
		skyboxNode = smgr->addSkyBoxSceneNode(
		driver->getTexture("1_up.jpg"),
		driver->getTexture("1_dn.jpg"),
		driver->getTexture("1_lf.jpg"),
		driver->getTexture("1_rt.jpg"),
		driver->getTexture("1_ft.jpg"),
		driver->getTexture("1_bk.jpg"));
	}


	SKeyMap keyMap[8];
	keyMap[0].Action = EKA_MOVE_FORWARD;
	keyMap[0].KeyCode = KEY_UP;
	keyMap[1].Action = EKA_MOVE_FORWARD;
	keyMap[1].KeyCode = KEY_KEY_W;
                   
	keyMap[2].Action = EKA_MOVE_BACKWARD;
	keyMap[2].KeyCode = KEY_DOWN;
	keyMap[3].Action = EKA_MOVE_BACKWARD;
	keyMap[3].KeyCode = KEY_KEY_S;
                   
	keyMap[4].Action = EKA_STRAFE_LEFT;
	keyMap[4].KeyCode = KEY_LEFT;
	keyMap[5].Action = EKA_STRAFE_LEFT;
	keyMap[5].KeyCode = KEY_KEY_A;
                   
	keyMap[6].Action = EKA_STRAFE_RIGHT;
	keyMap[6].KeyCode = KEY_RIGHT;
	keyMap[7].Action = EKA_STRAFE_RIGHT;
	keyMap[7].KeyCode = KEY_KEY_D;
                   

	camera = smgr->addCameraSceneNodeFPS(0,100.0f,300.0f, -1, keyMap, 8);
	camera->setPosition(core::vector3df(0,0,-99));

	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		mapSelector, camera, core::vector3df(30,50,30),
		core::vector3df(0,-100,0), 100.0f, 
		core::vector3df(0,50,0));
	camera->addAnimator(anim);
	anim->drop();

	//** disable mouse cursor

	device->getCursorControl()->setVisible(false);

	// add billboard
	scene::IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
	bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
	bill->setMaterialTexture(0, driver->getTexture("particle.bmp"));
	bill->setMaterialFlag(video::EMF_LIGHTING, false);
	bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));

	//** Add alot of Kid Buu's.
	video::SMaterial material, material2, material3;
	material.Texture1 = driver->getTexture("buu.pcx"); //** load texture for buu
	material2.Texture1 = driver->getTexture("vegeta.pcx");
	material3.Texture1 = driver->getTexture("vhead.pcx");

	material.Lighting = true;
	material2.Lighting = true;
	material3.Lighting = true;

	scene::IAnimatedMesh* buu = smgr->getMesh("buu.md2"); //** load model for buu, picture a wireframe we wrap the texture(buu.pcx) around

	ModelNode_1 = smgr->addAnimatedMeshSceneNode(buu);
	ModelNode_1->setPosition(core::vector3df(-70,0,-90));
	ModelNode_1->setMD2Animation(scene::EMAT_JUMP);
	ModelNode_1->getMaterial(0) = material;

	ModelNode_1 = smgr->addAnimatedMeshSceneNode(buu);
	ModelNode_1->setPosition(core::vector3df(-70,0,-150));
	ModelNode_1->setMD2Animation(scene::EMAT_RUN);
	ModelNode_1->getMaterial(0) = material;
	
	ModelNode_1 = smgr->addAnimatedMeshSceneNode(buu);
	ModelNode_1->setPosition(core::vector3df(-70,0,-210));
	ModelNode_1->setMD2Animation(scene::EMAT_ATTACK);
	ModelNode_1->getMaterial(0) = material;

	ModelNode_1 = smgr->addAnimatedMeshSceneNode(buu);
	ModelNode_1->setPosition(core::vector3df(-70,0,-270));
	ModelNode_1->setMD2Animation(scene::EMAT_WAVE);
	ModelNode_1->getMaterial(0) = material;

	ModelNode_1 = smgr->addAnimatedMeshSceneNode(buu);
	ModelNode_1->setPosition(core::vector3df(-70,0,-320));
	ModelNode_1->setMD2Animation(scene::EMAT_FLIP);
	ModelNode_1->getMaterial(0) = material;

	ModelNode_1 = smgr->addAnimatedMeshSceneNode(buu);
	ModelNode_1->setPosition(core::vector3df(-70,0,-380));
	ModelNode_1->setMD2Animation(scene::EMAT_DEATH_FALLBACK);
	ModelNode_1->getMaterial(0) = material;

	scene::IAnimatedMesh* vegeta = smgr->getMesh("vegeta.md2");
	scene::IAnimatedMesh* vhead = smgr->getMesh("vhead.md2");

	ModelNode_1 = smgr->addAnimatedMeshSceneNode(vegeta);
	ModelNode_1->setPosition(core::vector3df(-70,0,-420));
	ModelNode_1->setMD2Animation(scene::EMAT_FLIP);
	ModelNode_1->getMaterial(0) = material2;

	//** vegeta requires two models for his head and body

	ModelNode_1 = smgr->addAnimatedMeshSceneNode(vhead);
	ModelNode_1->setPosition(core::vector3df(-70,0,-420));
	ModelNode_1->setMD2Animation(scene::EMAT_FLIP);
	ModelNode_1->getMaterial(0) = material3;

	driver->beginScene(true, true, 0);
	core::triangle3df tri;
	driver->setTransform(video::ETS_WORLD, core::matrix4());
	driver->setMaterial(material);
	driver->draw3DTriangle(tri, video::SColor(0,255,0,0));


	material.Texture1 = 0;
	material.Lighting = false;

	//** Add a light

	smgr->addLightSceneNode(0, core::vector3df(-60,100,400),
		video::SColorf(0.0f,1.0f,1.0f,1.0f),
		900.0f);


	scene::ISceneNode* selectedSceneNode = 0;
	scene::ISceneNode* lastSelectedSceneNode = 0;

	int lastFPS = -1;

	while(device->run())
	{
		driver->beginScene(true, true, 0);

		smgr->drawAll();


		core::line3d<f32> line;
		line.start = camera->getPosition();
		line.end = line.start + (camera->getTarget() - line.start).normalize() * 1000.0f;

		core::vector3df intersection;
		core::triangle3df tri;

		if (smgr->getSceneCollisionManager()->getCollisionPoint(
			line, mapSelector, intersection, tri))
		{
			bill->setPosition(intersection);
				
			driver->setTransform(video::ETS_WORLD, core::matrix4());
			driver->setMaterial(material);
			driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
		}


		selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);

		if (lastSelectedSceneNode)
			lastSelectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, true);

		if (selectedSceneNode == LevelNode || selectedSceneNode == bill)
			selectedSceneNode = 0;

		if (selectedSceneNode)
			selectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

		lastSelectedSceneNode = selectedSceneNode;


		/*
		That's it, we just have to finish drawing.
		*/

		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			
	
			wchar_t tmp[1024];
			swprintf(tmp, 1024, L"A Game A02 - by fritz (fps:%d) Triangles:%d", 
				fps, driver->getPrimitiveCountDrawn());

			device->setWindowCaption(tmp); //** Won't work on >WIN XP
			lastFPS = fps;
		}
	}

	device->drop();

}





bool CGame::OnEvent(SEvent event)
{
	if (camera)
	{
		return camera->OnEvent(event);
	}
	
	if(event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
	{
		switch(event.KeyInput.Key)
		{
			case KEY_ESCAPE:
			{
				ExitProcess(0);
				return true;
			}
			
			return true;
			
		}
	}
		/*
		We send all other key and mouse input to the currently active camera
		if there is	one, so that the camera can move itself.
		*/

	return false;
}
PLEASE HELP!!!!!!! I'm going to die! this is driving me nuts!
fritz

Post by fritz »

Okay, I changed the subsystem to windows and did a couple of things, so now it compiles AND runs...

But thing is, nothing shows up... It just changes my cursor to the hour glass for a minute... It doesn't popup the game window, show my loading screen, or even let me play the game...

So I'm thinking there might be a problem with the way I'm calling run(); (see the function in Game.cpp above) in my int WINAPI WinMain function... where i declare game as CGame and game.run();... if thats good then I guess there is something wrong with my run() function...

Please help!

Regards,
Zak Farrington
fritz

Post by fritz »

Some one please help :(
Homer
Posts: 58
Joined: Tue Nov 18, 2003 7:11 pm
Location: Germany

Post by Homer »

I haven't read your whole code, because I haven't much time yet. I would recommend you to set an halt point (not sure if this is the correct translation of the german "Haltepunkt") at the beginning of your run-procedure and then start your application in debug mode to check if your program runs correctly.
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

German: Haltepunkt
English: Critical point (Google ;) )
Frensh: Halte
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
fritz

Post by fritz »

I have set a breakpoint, and it runs all the code up to device... Once it trys to inti device it fails and the whole app hangs... Keep in mind that the code works fine in int main, just when im calling it from my main function as
CGame game;
game.run();

is where it does not run, and just hangs
Miwa
Posts: 28
Joined: Wed Feb 18, 2004 10:48 pm

Post by Miwa »

Make sure you have the right crt linked in. I usually use Multithreaded DLL (look in code generation tab) for the CRT. You should use the same as the irrlicht dll does.
fritz

Post by fritz »

Uhh, could you explain more?

Btw I don't know much about multithreading
Post Reply