Tuesday, January 6, 2015

Getting Started with SFML and Linux.

This blog is meant to be a design journal as a 2d game engine evolves. It will be used as a record of design changes as this game engine is developed. The purpose of this game engine is not to re-invent the wheel for low level hardware interfaces. For this reason, the game engine will rely on the Simple and Fast Multimedia Library (SFML). This low level may be abstracted out later to allow for other low level libraries on different platforms.

This game engine will be developed on Linux and ported to other platforms. The game engine will be used to develop 2d platformers. I intend to have the engine support side scrollers and top down 2d games. 

There are plenty of tutorials regarding SFML out there so I will not be discussing the functionality provided by SFML unless it specifically drives design changes to the engine.

The primary functionality I wish to provide in the engine is to manage the entities or sprites that a game will need in order to remove that logic from any games that are developed with the library.

 // Initializes the engine  
 //   
 // This function sets up the rendering window for the engine.  
 // The input parameter iWindowName will be the title given to the window.  
 bool Engine::init(const char* iWindowName)  
 {  
   m_Window = new sf::RenderWindow(sf::VideoMode(m_Width,m_Height), iWindowName);  
   if(m_Window != NULL)  
   {  
     return false;  
   }  
   m_EntityManager = &EntityManager::getInstance();  
   m_TextureManager = &TextureManager::getInstance();  
   return true;  
 };  

The above code provides a basis for what we'll be doing. Initialization of the engine will setup the application window using SFML. The initialization will also record the singleton classes for the entity and texture managers.

The texture manager will ensure that any sprite needing drawn will use the appropriate texture and prevent the same texture from being created multiple times and thus slowing down the video card.

The entity manager will record all entities on the screen such as enemies, tiles, bullets, etc.
 
 // Cyclical loop for the engine  
 void Engine::loop()  
 {  
   while(m_Window->isOpen())  
   {  
     // Check for events like closures  
     handleInput();  
     // Update  
     update();  
     // Render  
     render();  
   }  
 };  

The above code shows the basis for the main engine loop. This should be done in its own thread. These will change as development continues.

No comments:

Post a Comment