示例#1
0
bool Engine::StartUp()
{
	
	
	#ifdef _DEBUG
	DevDrop("Starting Engine.");
	#endif

	if(InitWindow() == false || BootGL() == false) //If unable to initialize window or boot OpenGL
	{
	#ifdef _DEBUG
		DevError("Error starting engine! Shutting down.");
		SDL_Quit();
	#endif // _DEBUG
		return false;
	}

	if(DisableVSync() == false)
	{
		#ifdef _DEBUG
		DevError("Error Disabling VSync, non-critical.");
		#endif
	}
	else
	{
		#ifdef _DEBUG
		DevDrop("VSync Disabled!");
		#endif
	}

	#ifdef _DEBUG
	DevDrop("Engine Started Successfully");
	#endif // _DEBUG

	GraphicsM.Precache_Sheets(); //Precache sheets, they can be called from the GraphicsMananger via pointers.
	#ifdef _DEBUG
	DevDrop("Sprite sheets precached and ready!");
	#endif // _DEBUG

	SetupAudio();

	gCam.Camera.x = 0;
	gCam.Camera.y = 0;
	gCam.Camera.w = GetGameScreen()->w;
	gCam.Camera.h = GetGameScreen()->h;

	SDL_EnableKeyRepeat(40,1); //Enable key repeating. After holding a key down for 40ms it will repeat the key press once.

	SetupLevels(); //This function will be deprecated soon. :(200): 

	Menu->Setup(); //Currently disabled, sets up the Menu initially.

	return true;
}
示例#2
0
GLuint GraphicsCore::Load_Image( string filename)
{

	pngInfo info; //Prepare the PNG info

	GLuint Texture;

	glGenTextures(1, &Texture); // Prepare the Texture to be used as an actual OpenGL Texture.

	Texture = pngBind(filename.c_str(),
						PNG_NOMIPMAP,
						PNG_ALPHA,
						&info,
						GL_CLAMP,
						GL_LINEAR,
						GL_LINEAR); //Bind the png file to the GLuint Texture.

	if(Texture == 0)
	{
		#ifdef _DEBUG
		DevError("Texture not found! Name:%s", filename.c_str()); //If it didn't work, the Texture wasn't found.
		#endif

	}
	return Texture; //Return the finished .png texture.
}
示例#3
0
Sheet GraphicsCore::Get_SpriteSheet( int SheetID )
{
	if(SheetID >= 0 && SheetID <= 19)
	{
		return Precached_Sheets[SheetID];
	}

	#ifdef _DEBUG
	DevError("Unable to find requested sprite sheet. ID may be wrong?");
	#endif
	return Precached_Sheets[20];
}
IGame *CNativeGameLoader::LoadGame(const tString &asName)
{
	CreateInterfaceFn fnCreateInterface = Sys_GetFactory(static_cast<CSysModule*>(mpGameLib));
	//CreateInterfaceFn fnCreateInterface = LibUtil::GetFactory(mpGameLib);
	
	IGame *pGame = nullptr;
	
	if(fnCreateInterface)
	{
		DevMsg("Detected native magenta format...");
		pGame = (IGame*)fnCreateInterface(MGT_GAME_INTERFACE_VERSION, nullptr);
	};
	
	// Is interface valid?
	if(!pGame)
	{
		DevError("Unsupported format!");
		DevError("Failed to load the game dll!");
		return nullptr;
	};
	
	return pGame;
};
示例#5
0
// update server:
// MB move all this code into game class...
// We need to update clients aka players anyway
// It's logically right that game is interacting with players...
// read packets, check timeouts, calc pings
// update physics world, game, game world - problem with updater is here
// send packets back to clients
//
// now update client:
bool CEngineCore::Frame()
{
	//assert(mbInitialized);
	
	// Not initialized or want to close
	if(!mbInitialized || mbWantClose)
	{
		DevError("Called core run but it's not initialized yet!");
		//return eEngineRunResult_NotInitialized; //return eEngineRunResult_Error;
		return false;
	};
	
	// Update console
	// Check for commands typed to the host
	//GetConsoleCommands();
	
	// Process console commands
	//mpConsole->ExecCmdBuffer();
	
	// Decide the simulation time
	//if(!FilterTime(fNewTime - fOldTime))
		//return true;
	
	mpEventManager->PostEvent(eEngineEvent::PreFrame);
	
	// Update logic
	if(mpLogicTimer->WantUpdate() && !mbWantClose)
	{
		mpUpdater->Update(mpLogicTimer->GetStepSize()); // Or Tick()
		// update world
		// update clients
		
		mpEventManager->PostEvent(eEngineEvent::PostUpdate);
	};
	
	mpLogicTimer->EndUpdateLoop();
	
	//mpUpdater->PostUpdate(mpLogicTimer->GetStepSize());
	
	mpEventManager->PostEvent(eEngineEvent::RenderFrame);
	
	mpEventManager->PostEvent(eEngineEvent::PostRender);
	
	mpEventManager->PostEvent(eEngineEvent::PostFrame);
	return true;
};
示例#6
0
bool Engine::InitWindow()
{
	Window = SDL_SetVideoMode(800,600,32,SDL_OPENGL | SDL_RESIZABLE); //Initialize the screen, make it able to printed to via OpenGL and make it resizeable.

	if(!Window) //If window does not exist.
	{
		#ifdef _DEBUG
		DevError("Unable to set SDL Video.");
		#endif // _DEBUG
		return false;
	}

	#ifdef _DEBUG
	DevDrop("Window Initialized!");
	#endif // _DEBUG

	SDL_WM_SetCaption("Project Lerum",NULL);
	return true;
}
示例#7
0
bool Engine::SetupAudio()
{
	int audio_rate = 44100;
	Uint16 audio_format = AUDIO_S16;
	int audio_channels = 2;
	int audio_buffers = 4096;

	if(Mix_OpenAudio(audio_rate,audio_format,audio_channels,audio_buffers))
	{
		#ifdef _DEBUG
		DevError("Unable to open audio system!!!");
		#endif
		return false;
	}
	#ifdef _DEBUG
	DevDrop("Audio system setup successfully!");
	#endif
	return true;
}
示例#8
0
bool CEngineCore::Init(const char *asGameFolder, const char *asCmdLine, bool abDedicated, CreateInterfaceFn afnLauncherFactory)
{
	// Already initialized
	if(mbInitialized)
	{
		DevWarning("Called core init while it's already initialized!");
		return true;
	};
	
	LogMsg("Initializing the core module...");
	//LogMsg("\t%s Magenta (build %i) started at %s"/*, s_wcd.title, ENGINE_BUILD, Q_timestamp(TIME_FULL)*/);
	
	DevMsg("Magenta Core\nVersion %d.%d.%d/%s (%s)", ENGINE_VERSION_MAJOR, ENGINE_VERSION_MINOR, ENGINE_VERSION_REV, ENGINE_VERSION_STRING, asGameFolder);
	DevMsg("Exe build: " __TIME__ " " __DATE__ " (%04d)", ENGINE_BUILD /*build_number()*/);
	//DevMsg("Protocol version: %d", GetProtocolVersion());
	
	// 30 frames cap by default
	int nFrameCount = 30;
	
	// 100 frames for dedicated mode (equals to sys_ticrate 100)
	if(abDedicated)
		nFrameCount = 100;
	
	//=============================================================================================
	
	mpLogicTimer = std::make_unique<CLogicTimer>(nFrameCount);
	mpUpdater = std::make_unique<CUpdater>();
	
	//mpConsole = std::make_unique<CNullConsole>();
	
	//mpGameInfo = std::make_shared<CNullGameInfo>();
	//mpGameInfoHandler = std::make_unique<CNullGameInfoHandler>();
	
	//mpHost = std::make_unique<CEngineHost>();
	
	mpPluginManager = std::make_unique<CPluginManager>(afnLauncherFactory);
	
	mpGame = std::make_unique<CGameRef>();
	mpInput = std::make_unique<CInput>();
	
	/*
	mpGameServer = std::make_unique<CGameServer>();
	mpEdictHandler = std::make_unique<CEdictHandler>();
	mpEngineFuncs = std::make_unique<CEngineFuncs>(nullptr, nullptr, mpEdictHandler.get());
	
	if(!mpGameServer->Init())
		return false;
	*/
	
	//=============================================================================================
	
	//if(!abDedicated)
		// Init client side
	
	mpPluginManager->LoadPluginList("plugins");
	
	mpEventManager->PostEvent(eEngineEvent::Init);
	
	mpLogicTimer->Reset();
	
	tString sFailReason = "";
	bool bInitFailed = false;
	
	//if(!mpConsole->Init())
	//{
		//sFailReason += "\t- Couldn't init console module!\n";
		//return false;
	//};
	
	if(!mpGame->LoadFromFile(std::move(tString(asGameFolder) + "/bin/game") /*mpGameInfo->msGameDLLPath*/))
		return false;
	
	if(!mpGame->Init())
		return false;
	
	// Allow mice or other external controllers to add commands
	
	if(!abDedicated)
		mpUpdater->AddGlobalUpdate(mpInput.release());
	
	//mpUpdater->AddGlobalUpdate(mpNetwork.release());
	//mpUpdater->AddGlobalUpdate(mpPhysics.release());
	//mpUpdater->AddGlobalUpdate(mpScene.release());
	mpUpdater->AddGlobalUpdate(mpGame.release());
	
	mpUpdater->AddContainer("Default");
	mpUpdater->SetContainer("Default");
	
	/*
	IBaseInterface *pInterface = ModuleInit::TryInit(NETWORK_INTERFACE_VERSION, nullptr);
	
	IBaseInterface *ModuleInit::TryInit(const char *asInterfaceName, int &retval)
	{
		IBaseInterface *pInterface;
	
		if(!(pInterface = afnLauncherFactory(asInterfaceName, retval)))
		{
			sFailReason += "\t- Can't get " + asInterfaceName + " module!\n";
	
			// if not failed yet - now is the time
			if(!mbInitFailed)
				mbInitFailed = true;
		};
	};
	*/
	
	//if(ModuleInit::IsInitFailed())
		//return false;
	
	/*if(!(mpNetwork = (INetwork*)afnLauncherFactory(NETWORK_INTERFACE_VERSION, nullptr)))
	{
		sFailReason += "\t- Can't get network module!\n";
		bInitFailed = true;
	};
	
	if(!(mpFileSystem = (IFileSystem*)afnLauncherFactory(FILESYSTEM_INTERFACE_VERSION, nullptr)))
	{
		sFailReason += "\t- Can't get filesystem module!\n";
		bInitFailed = true;
	};*/
	
	/*
	if(!(mpPhysics = (IPhysics*)afnLauncherFactory(PHYSICS_INTERFACE_VERSION, nullptr))) // is this needed here?
	{
		sFailReason += "\t- Can't get physics module!\n";
		//bInitFailed = true;
	};
	*/
		
	if(bInitFailed)
	{
		DevError("Can't init the core module!\n(Reason(s):\n%s", sFailReason.c_str());
		return false;
	};
	
	msGameFolder = asGameFolder;
	
	// Convert liblist.gam file into gameinfo.txt if exist (presume that gameinfo.txt is exist)
	//if(mpFileSystem->IsFileExists(msGameFolder + "/gameinfo.txt")
		//mpGameInfo->LoadFromFile(msGameFolder + "/gameinfo.txt");
	//else if(mpFileSystem->IsFileExists(msGameFolder + "/liblist.gam"))
		//mpGameInfoHandler->ConvertToGameInfo(msGameFolder + "/liblist.gam");
	//if(!pLowLevelFileSystem->IsFileExist(msGameFolder + "/gameinfo.txt") && pLowLevelFileSystem->IsFileExist(msGameFolder + "/liblist.gam"))
		//mpGameInfoHandler->ConvertToGameInfo(msGameFolder + "/liblist.gam");
	//else
		//mpGameInfoHandler->CreateDefaultGameInfo()->SaveToFile(msGameFolder + "/gameinfo.txt");
	
	// Todo: check if file exist inside LoadFromFile method
	//mpGameInfo->LoadFromFile(msGameFolder + "/gameinfo.txt");
	
	mpEventManager->PostEvent(eEngineEvent::PostInit); // Broadcast
	
	mbInitialized = true;
	return true;
};
示例#9
0
bool Engine::BootGL()
{
	const GLubyte* card = glGetString(GL_VERSION);
	if(!card)
	{
		DevError("Unable to detect OpenGL version, critical error!!!");
		return false;
	}
	else
	{
		DevDrop("OpenGL Version detected:%s",card);
	}



	SDL_GL_SetAttribute(SDL_GL_RED_SIZE,	8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,	8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,	8);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,	8);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 8);
//	SDL_GLattr(SDL_GL_SWAP_CONTROL,0);
	
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);

	GLenum glewError = glewInit();
	if(glewError != GLEW_OK)
	{
		DevError("Error initializing GLEW!!! Aborting Startup!!!");
		Sleep(5000);
		exit(0);
	}
	else
	{
		DevDrop("GLEW Successfully initialized.");
	}

	if(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
		DevDrop("GLSL Prepared");
	else
		DevError("GLSL Not prepared");
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glShadeModel (GL_SMOOTH);
	glDepthFunc(GL_LEQUAL);
	glAlphaFunc ( GL_GREATER, 0.45 ) ;
	glEnable ( GL_ALPHA_TEST ) ;
	glClearColor(0.0,0.0,0.0,1.0);
	glViewport(0, 0, Window->w,Window->h);
	glOrtho(0.0,(GLdouble)Window->w, (GLdouble)Window->h,0.0,0.0,1.0);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	#ifdef _DEBUG
	DevDrop("OpenGL Booted!");
	#endif // _DEBUG

	GraphicsM.SetupFBO();
	
	return true;
}