/****************************************************************************** * File - world.cpp * Author - Joey Pollack * Date - 2022/01/12 (y/m/d) * Mod Date - 2022/01/20 (y/m/d) * Description - Manages a game "world". A world is made up of regions which * are subdivisions of the world. Each region contains: a set * of images for the maps layers, a list of objects that spawn * in this region and static collision data. ******************************************************************************/ #include "world.h" #include #include #include #include #include #include "entity.h" namespace lunarium { // World::World(Camera* pCam, Sizei region_size, Sizei world_size) // : mpCamera(pCam), mRegionSize(region_size), mpWorldScript(nullptr), mWorldSize(world_size) // { // mActiveRegion = { 0, 0 }; // } World::World() { } void World::OnLoad() { // TODO: Call OnLoad in the world script and on each region script } void World::OnUnload() { // TODO: Call OnUnLoad in the world script and on each region script } void World::Update(float dt) { // TODO: Call Update in the world script and on each region script } void World::Render(Graphics* pGraphics) const { // TODO: Call Render in the world script and on each region } void World::RenderToTexture(Graphics* pGraphics, Image* pTexture) const { } entt::registry* World::GetEntityRegistry() { return &mECSRegistry; } LUUID World::CreateEntity() { //Logger::Error(LogCategory::GAME_SYSTEM, "World::CreateEntity not implemented!"); Entity* new_ent = new Entity(*this); if (mEntitiesByUUID.find(new_ent->GetUUID()) != mEntitiesByUUID.end()) { Logger::Warn(LogCategory::GAME_SYSTEM, "UUID collision when creating new entity! UUID: %d", new_ent->GetUUID()); } mEntitiesByUUID[new_ent->GetUUID()] = new_ent; mEntities.push_back(new_ent); return new_ent->GetUUID(); } Entity* World::GetEntity(LUUID id) { if (mEntitiesByUUID.find(id) == mEntitiesByUUID.end()) { Logger::Warn(LogCategory::GAME_SYSTEM, "Entity with id: %d not found.", id); } return mEntitiesByUUID[id]; } unsigned int World::GetNumEntities() const { return mEntities.size(); } std::vector::iterator World::EntitiesBegin() { return mEntities.begin(); } bool World::EntitiesIsEnd(std::vector::iterator& iter) { return iter == mEntities.end(); } }