namespace sgda { // GLOBALS ResourceManager ResourceManager::d_manager = ResourceManager(); ImageDataFactory ResourceManager::d_imageFactory = ImageDataFactory(); ConfigDataFactory ResourceManager::d_configFactory = ConfigDataFactory(); // MEMBER FUNCTIONS void ResourceManager::postTick() { if ( d_frame == ( unsigned int )-1 ) { d_frame = 0; } if ( !( ++d_frame % 8 ) ) { d_images.clean(); } else if ( ( d_frame + 4 ) % 8 ) { d_configs.clean(); } } } // End nspc sgda
int main() { ResourceManager resourceManager = ResourceManager(); resourceManager.addResourceDirectory("res/"); sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "ECS Test"); EntityManager entityManager = EntityManager(&window, 100); for (int i = 1; i < 10000; ++i) { int temp = entityManager.createEntity(sf::Vector2f(WINDOW_X * float(rand()) / RAND_MAX, WINDOW_Y * float(rand()) / RAND_MAX)); entityManager.attachComponent(temp, RenderComponent(resourceManager.getTexture("player.png"))); entityManager.attachComponent(temp, PhysicsComponent(sf::Vector2f(100 * (float(rand()) / RAND_MAX - 0.5), 100 * (float(rand()) / RAND_MAX - 0.5)))); } // Remove some entities. for (int i = 1; i < 3; ++i) { entityManager.destroyEntity(i); } // Remove some components. for (int i = 3; i < 10; ++i) { entityManager.detachComponent(i, RENDER); } sf::Clock clock; while (window.isOpen()) { // Handle events. sf::Event event; while (window.pollEvent(event)) { if(event.type == sf::Event::Closed) { window.close(); } } float frametime = clock.restart().asSeconds(); std::cout << (1 / frametime) << std::endl; window.clear(sf::Color::White); entityManager.update(frametime); window.display(); } }
void Engine::Initialize(GameProperties props) { this->LaunchMessage(); State.Paused = false; State.Quit = false; Properties = props; Resources = ResourceManager(); Renderer = new RendererSDL(); //Renderer = new RendererOpenGL(); if(SDL_Init( SDL_INIT_VIDEO ) < 0) { printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); return; } Renderer->Initialize(); DefaultProperties(); Precache(); Start(); GameLoop(); Cleanup(); SDL_Quit(); }
void TexturePacker::load_resources(Canvas &canvas, const std::string &filename) { resources = ResourceManager(filename); // TODO: Delete items before clearing resource_items.clear(); std::vector<std::string> resource_names = resources.get_resource_names(); std::vector<std::string>::iterator resource_it; for(resource_it = resource_names.begin(); resource_it != resource_names.end(); ++resource_it) { std::string resource_id = (*resource_it); Resource resource = resources.get_resource(resource_id); resource_items.push_back(load_resource(canvas, resource_id, resource, resources)); } }