World *WorldService::WorldLoader::loadWorlds(const std::string &mainWorldName) { // load main world LoadedWorld &mainWorld = loadWorld(mainWorldName, false); if (mainWorld.failed()) { error("Failed to load main world"); return nullptr; } WorldTreeNode worldTreeRoot; worldTreeRoot.value = mainWorld.world; // allocate main world building IDs for (auto &building : buildings) { Logger::logDebuggier(format("Found building %1% '%2%' in main world", _str(building.insideWorldID), building.insideWorldName)); Logger::pushIndent(); loadWorld(building.insideWorldName, true, building.insideWorldID); Logger::popIndent(); } // transfer building IDs to doors for (auto &door : mainWorld.doors) { LoadedBuilding *owningBuilding = findDoorBuilding(door); if (owningBuilding == nullptr) { error("A door at (%1%, %2%) is not in any buildings!", _str(door.tile.x), _str(door.tile.y)); return nullptr; } door.doorTag = DOORTAG_WORLD_ID; door.worldID = owningBuilding->insideWorldID; owningBuilding->doors.push_back(door); } std::set<WorldID> visitedWorlds; // load all worlds recursively without connecting doors discoverAndLoadAllWorlds(mainWorld, mainWorld.world->getID(), visitedWorlds); visitedWorlds.clear(); // connect up the doors connectDoors(worldTreeRoot, mainWorld, visitedWorlds); return mainWorld.world; }
/* MAIN */ int main(int argc, char **argv){ if(argc < 6){ printf("ERROR: too few arguments.\n"); fflush(stdout); /* force it to go out */ exit(1); } FILE* input = fopen(argv[1], "r"); if(input == NULL){ printf("ERROR: file does not exist.\n"); fflush(stdout); /* force it to go out */ exit(1); } wolfBreedingPeriod = atoi(argv[2]); squirrelBreedingPeriod = atoi(argv[3]); wolfStarvationPeriod = atoi(argv[4]); int noOfGenerations = atoi(argv[5]); loadWorld(input); // fprintf(stdout, "Initial world configuration after loading from file:\n"); // fflush(stdout); /* force it to go out */ // printWorld2d(stdout); /* pressEntertoContinue(); */ worldLoop(noOfGenerations); printWorld(); fclose(input); return 0; }
void setupGame(bool loadUpWorld) { currentLevel = 1; // Reset entity manager. memset(&eManager, 0, sizeof(eManager)); sf2d_set_clear_color(RGBA8(0x82, 0x6D, 0x6C, 0xFF)); if (!loadUpWorld) { initNewMap(); initPlayer(); airWizardHealthDisplay = 2000; int i; for (i = 0; i < 5; ++i) { trySpawn(500, i); } addEntityToList(newAirWizardEntity(630, 820, 0), &eManager); player.p.hasWonSaved = false; } else { initPlayer(); loadWorld(currentFileName, &eManager, &player, (u8*) map, (u8*) data); } initMiniMap(loadUpWorld); shouldRenderMap = false; mScrollX = 0; mScrollY = 0; zoomLevel = 2; sprintf(mapText,"x%d",zoomLevel); initGame = 0; }
int main(int len, char *args[]) { // Grundwerte für die Erzeugung der Welt // werden aus den Initialisierungswerten gelesen. int rows = 21; int cols = 35; int amount_cells = 100; World w; int i; for (i = 1; i < len; i++) { if (strcmp(args[i], "-l") == 0) { w = loadWorld(args[i+1]); return execGame(w); } else if (strcmp(args[i], "-r") == 0) { rows = atoi(args[++i]); } else if (strcmp(args[i], "-c") == 0) { cols = atoi(args[++i]); } else if (strcmp(args[i], "-a") == 0) { amount_cells = atoi(args[++i]); } } w = makeRandomWorld(rows, cols, amount_cells); return execGame(w); }
World::World(std::string path) { mPlayer = std::make_shared<Player>(Assets::sprites["bluepeewee"], sf::Vector2f()); mCollideables.push_back(mPlayer); mGravity = sf::Vector2f(0.f, 10.f); mSpawnPoint = sf::Vector2f(0.f, 0.f); mBoundaries = sf::FloatRect(0.f, 0.f, 800.f, 600.f); // left, top, width, height mBackground = sf::Sprite(Assets::sprites["background"].mTexture); mBlackHole = std::make_shared<Blackhole>(Assets::sprites["blackhole"], sf::Vector2f(), 0); loadWorld(path); }
//--------------------------------------------------------------- // Purpose: //--------------------------------------------------------------- void CEntityTypeWorld::OnParamChanged( const std::string &key, const std::string &oldval, const std::string &newval ) { BaseClass::OnParamChanged(key, oldval, newval); if( key.compare("filename") == 0 ) loadWorld(); else if( key.compare("suntex") == 0 ) GetRenderInterfaces()->GetRendererInterf()->GetSunFlare()->SetTexture(newval.c_str()); else if( key.compare("sunsize") == 0 ) GetRenderInterfaces()->GetRendererInterf()->GetSunFlare()->SetSize(StrUtils::GetFloat(newval)); else if( key.compare("seaColorDark") == 0 ) GetRenderInterfaces()->GetRendererInterf()->SetSeaColorDark(StrUtils::GetVector3(newval) / 255.0f); else if( key.compare("seaColorBright") == 0 ) GetRenderInterfaces()->GetRendererInterf()->SetSeaColorBright(StrUtils::GetVector3(newval) / 255.0f); }
void Minutor::open() { QString dirName = QFileDialog::getExistingDirectory(this, tr("Open World")); if (!dirName.isEmpty()) { QDir path(dirName); if (!path.exists("level.dat")) { QMessageBox::warning(this, tr("Couldn't open world"), tr("%1 is not a valid Minecraft world") .arg(dirName), QMessageBox::Cancel); return; } loadWorld(dirName); } }
hkDemo::Result WorldSnapshotWithContactPointsDemo::stepDemo() { Result r = hkDefaultPhysicsDemo::stepDemo(); if( r != DEMO_OK ) { return r; } // The first button in the pad will load the last saved scene if( m_env->m_gamePad->wasButtonPressed( HKG_PAD_BUTTON_1 ) ) { hkString filename = hkAssetManagementUtil::getFilePath( SCRATCH_FILE ); hkIstream in(filename.cString()); if( in.isOk() ) { cleanupWorld(); cleanupGraphics(); hkpWorld::IgnoreForceMultithreadedSimulation ignoreForceMultithreaded; m_world = loadWorld(filename.cString(), &m_physicsData, &m_loadedData); m_debugViewerNames.pushBack( hkpActiveContactPointViewer::getName() ); m_debugViewerNames.pushBack( hkpInactiveContactPointViewer::getName() ); setupGraphics(); } else { m_env->m_textDisplay->outputText("Please save before attempting to load", 20U, m_env->m_window->getHeight()/2, 0xffffffffU, 60); } } else if (m_env->m_gamePad->wasButtonPressed (HKG_PAD_BUTTON_2) ) { // The second button in the pad will save the current scene saveWorld(m_world, SCRATCH_FILE, true); } else if (m_env->m_gamePad->wasButtonPressed (HKG_PAD_BUTTON_3) ) { // The second button in the pad will save the current scene saveWorld(m_world, SCRATCH_FILE, false); } m_world->lock(); m_world->updateCollisionFilterOnWorld( HK_UPDATE_FILTER_ON_WORLD_FULL_CHECK, HK_UPDATE_COLLECTION_FILTER_PROCESS_SHAPE_COLLECTIONS); m_world->unlock(); return DEMO_OK; }
string Display::getWorld() { // DEBUG //////////////// if (isLoaded_ == false) { loadWorld(); } //////////////// stringstream world; for (auto& iter : m_map) { world << iter.second.serialize(true); } world << "End"; return world.str(); }
void Engine::begin() { // seed the random generator std::srand(static_cast <unsigned> (std::time(0))); // setup the begin world loadWorld(_settings->get("application", "world")); // enter the core game loop Timer t; double lastRender = 0; while (!_window->shouldClose()) { if (_nextWorld != nullptr) { if (_world != nullptr) { _world->destroyed(); delete _world; } _world = _nextWorld; _world->added(); _nextWorld = nullptr; } double elapsed = t.getDeltaTimeSeconds(); //lastRender += elapsed; //if (lastRender >= 1./FPS) //{ _window->updateInput(); _loader->getFileWatcher()->update(); _luaengine->setGlobal("deltatime", elapsed); update((float)elapsed); render(); _window->updateWindow(); lastRender -= 1./FPS; //} } }
WorldSnapshotWithContactPointsDemo::WorldSnapshotWithContactPointsDemo( hkDemoEnvironment* env) : hkDefaultPhysicsDemo(env) { hkpWorld::IgnoreForceMultithreadedSimulation ignoreForceMultithreaded; // Setup the camera { hkVector4 from(10, -10, 6); hkVector4 to(0, 0, -4); hkVector4 up(0, 0, 1); setupDefaultCameras( env, from, to, up ); } // Load the startup scene { // Load the world. m_world = loadWorld(ORIGINAL_FILE, &m_physicsData, &m_loadedData); m_world->lock(); m_debugViewerNames.pushBack( hkpActiveContactPointViewer::getName() ); m_debugViewerNames.pushBack( hkpInactiveContactPointViewer::getName() ); // Disable culling setGraphicsState(HKG_ENABLED_CULLFACE, false); // Enable wire frame display mode setGraphicsState(HKG_ENABLED_WIREFRAME, true); // Setup graphics setupGraphics(); m_world->unlock(); } // Disable warning: 'm_contactRestingVelocity not set, setting it to REAL_MAX, so that the new collision restitution code will be disabled' hkError::getInstance().setEnabled(0xf03243ed, false); }
void setupGame(bool loadUpWorld){ currentLevel = 1; // Reset entity manager. memset(&eManager, 0, sizeof(eManager)); sf2d_set_clear_color(RGBA8(0x82, 0x6D, 0x6C, 0xFF)); if(!loadUpWorld){ initNewMap(); initPlayer(); airWizardHealthDisplay = 2000; int i; for(i=0;i<5;++i){ trySpawn(500, i); } addEntityToList(newAirWizardEntity(630,820,0), &eManager); } else { initPlayer(); loadWorld(currentFileName, &eManager, &player, (u8*)map, (u8*)data); } initMiniMap(loadUpWorld); initGame = 0; }
void WorldService::WorldLoader::discoverAndLoadAllWorlds(LoadedWorld &world, WorldID lastWorldID, std::set<WorldID> &visitedWorlds) { if (visitedWorlds.find(world.world->getID()) != visitedWorlds.end()) return; visitedWorlds.insert(world.world->getID()); std::sort(world.doors.begin(), world.doors.end(), [] (const LoadedDoor &a, const LoadedDoor &/* b */) { return a.doorTag != DOORTAG_WORLD_SHARE; }); // iterate all doors found in last world for (LoadedDoor &door : world.doors) { // initialise negative/ascending doors if (door.doorID < 0) { door.doorTag = DOORTAG_WORLD_ID; door.worldID = lastWorldID; continue; } LoadedWorld *newWorld = nullptr; // find the other door with same world share if (door.doorTag == DOORTAG_WORLD_SHARE) { auto otherDoor = std::find_if(world.doors.begin(), world.doors.end(), [door](const LoadedDoor &d) { return d.doorTag != DOORTAG_WORLD_SHARE && d.worldShare == door.worldShare; }); if (otherDoor == world.doors.end()) { Logger::logError(format("Door %1% has an unknown world share tag '%2%'", _str(door.doorID), door.worldShare)); continue; } // share world ID door.worldID = otherDoor->worldID; } // load world else if (door.doorTag == DOORTAG_WORLD_NAME) { Logger::logDebuggiest(format("Door ID %1% loads world '%2%'", _str(door.doorID), door.worldName)); LoadedWorld &loadedWorld = loadWorld(door.worldName, true); if (loadedWorld.failed()) { Logger::logError(format("Cannot find building world '%1%', owner of door %2%", door.worldName, _str(door.doorID))); continue; } door.worldID = loadedWorld.world->getID(); newWorld = &loadedWorld; } else if (door.doorTag == DOORTAG_UNKNOWN) { Logger::logError(format("Door %1% has no assigned door tag", _str(door.doorID))); return; } if (newWorld == nullptr) newWorld = getLoadedWorld(door.worldID); discoverAndLoadAllWorlds(*newWorld, world.world->getID(), visitedWorlds); } }
void TestWorld::populate(){ qDebug()<<"Creating TestWorld"; loadWorld("data/levels/test.xml"); }
void Minutor::openWorld() { QAction *action = qobject_cast<QAction*>(sender()); if (action) loadWorld(action->data().toString()); }
WorldService::WorldLoader::LoadedWorld &WorldService::WorldLoader::loadWorld(const std::string &name, bool isBuilding) { return loadWorld(name, isBuilding, generateWorldID()); }
void Minutor::reload() { loadWorld(currentWorld); }
//--------------------------------------------------------------- // Purpose: //--------------------------------------------------------------- void CEntityTypeWorld::OnCreate( void ) { BaseClass::OnCreate(); loadWorld(); }
PlanetGravityDemo::PlanetGravityDemo( hkDemoEnvironment* env ) : hkDefaultPhysicsDemo(env) { hkString filename; // We have a different binary file depending on the compiler and platform filename.printf( "Resources/Physics/Levels/planetgravity_L%d%d%d%d.hkx", hkStructureLayout::HostLayoutRules.m_bytesInPointer, hkStructureLayout::HostLayoutRules.m_littleEndian ? 1 : 0, hkStructureLayout::HostLayoutRules.m_reusePaddingOptimization? 1 : 0, hkStructureLayout::HostLayoutRules.m_emptyBaseClassOptimization? 1 : 0 ); hkIstream infile( filename.cString() ); HK_ASSERT( 0x215d080c, infile.isOk() ); hkpWorld::IgnoreForceMultithreadedSimulation ignoreForceMultithreaded; // Disable warning: 'm_contactRestingVelocity not set, setting it to REAL_MAX, so that the new collision restitution code will be disabled' hkError::getInstance().setEnabled( 0xf03243ed, false ); // Load the startup scene { m_worldUp.set( 0.0f, 0.0f, 1.0f ); m_characterForward.set( 1.0f, 0.0f, 0.0f ); // Initialize hkpSurfaceInfo for storing the old ground info m_previousGround = new hkpSurfaceInfo(); m_framesInAir = 0; m_cameraForward.set( 1.0f, 0.0f, 0.0f ); m_cameraUp = m_cameraForward; m_cameraPosition.set( 20.0f, 1.0f, 35.0f ); m_detachedCamera = false; // Load the world. m_world = loadWorld( filename.cString(), &m_physicsData, &m_loadedData ); m_world->markForWrite(); setupDefaultCameras( env, m_cameraPosition, m_characterRigidBody->getPosition(), m_worldUp ); // Setup graphics setupGraphics(); forceShadowState(false); // Disable shadows setupSkyBox(env); { removeLights( m_env ); float v[] = { 0.941f, 0.941f, 0.784f }; m_flashLight = hkgLight::create(); m_flashLight->setType( HKG_LIGHT_DIRECTIONAL ); m_flashLight->setDiffuse( v ); v[0] = 0; v[1] = 1; v[2] = -0.5; m_flashLight->setDirection( v ); v[0] = 0; v[1] = -1000; v[2] = 0; m_flashLight->setPosition( v ); m_flashLight->setDesiredEnabledState( true ); env->m_displayWorld->getLightManager()->addLight( m_flashLight ); env->m_displayWorld->getLightManager()->computeActiveSet( HKG_VEC3_ZERO ); } // Set up the collision filter { hkpGroupFilter* filter = new hkpGroupFilter(); filter->disableCollisionsBetween(1, 1); m_world->setCollisionFilter(filter); filter->removeReference(); } // Go through all loaded rigid bodies for( int i = 0; i < m_physicsData->getPhysicsSystems().getSize(); i++ ) { const hkArray<hkpRigidBody*>& bodies = m_physicsData->getPhysicsSystems()[i]->getRigidBodies(); for( int j = 0; j < bodies.getSize(); j++ ) { hkString rbName( bodies[j]->getName() ); // If the rb is a planet (name is "planet*") if( rbName.beginsWith( "planet" ) ) { // If the body is a representation of a gravitational field (name: "*GravField"), // remove it from the simulation. if( rbName.endsWith( "GravField" ) ) { m_world->removeEntity( bodies[j] ); } // Otherwise, it's actually a planet. else { hkAabb currentAabb; const hkpCollidable* hullCollidable = HK_NULL; // Find the planet's gravity field hkpRigidBody* planetRigidBody = bodies[j]; hkString gravFieldRbName; gravFieldRbName.printf( "%sGravField", rbName.cString() ); hkpRigidBody* gravFieldRigidBody = m_physicsData->findRigidBodyByName( gravFieldRbName.cString() ); // If there's a GravField rigid body, then grab its collidable to be used for gravity calculation. if( gravFieldRigidBody ) { hullCollidable = gravFieldRigidBody->getCollidable(); gravFieldRigidBody->getCollidable()->getShape()->getAabb( gravFieldRigidBody->getTransform(), 0.0f, currentAabb ); } else { planetRigidBody->getCollidable()->getShape()->getAabb( planetRigidBody->getTransform(), 0.0f, currentAabb ); } // Scale up the planet's gravity field's AABB so it goes beyond the planet hkVector4 extents; extents.setSub4( currentAabb.m_max, currentAabb.m_min ); hkInt32 majorAxis = extents.getMajorAxis(); hkReal maxExtent = extents( majorAxis ); maxExtent *= 0.4f; // Scale the AABB's extents hkVector4 extension; extension.setAll( maxExtent ); currentAabb.m_max.add4( extension ); currentAabb.m_min.sub4( extension ); // Attach a gravity phantom to the planet so it can catch objects which come close SimpleGravityPhantom* gravityAabbPhantom = new SimpleGravityPhantom( planetRigidBody, currentAabb, hullCollidable ); m_world->addPhantom( gravityAabbPhantom ); gravityAabbPhantom->removeReference(); // Add a tracking action to the phantom so it follows the planet. This allows support for non-fixed motion type planets if (planetRigidBody->getMotion()->getType() != hkpMotion::MOTION_FIXED) { PhantomTrackAction* trackAction = new PhantomTrackAction( planetRigidBody, gravityAabbPhantom ); m_world->addAction( trackAction ); trackAction->removeReference(); } } } // if the rigid body is a launchpad (name: "launchPadSource*") else if( rbName.beginsWith("launchPadSource" ) ) { hkString targetName; // Find launchpad "target" (used to calculate trajectory when launching) targetName.printf( "launchPadTarget%s", rbName.substr( hkString::strLen("launchPadSource") ).cString() ); hkpRigidBody* target = m_physicsData->findRigidBodyByName( targetName.cString() ); HK_ASSERT2( 0x0, target, "All launchPadSource rigid bodies must have associated launchPadTargets." ); // Add a collision listener to the launchpad so it can apply forces to colliding rbs LaunchPadListener* launchPadListener = new LaunchPadListener( target->getPosition() ); bodies[j]->addCollisionListener( launchPadListener ); bodies[j]->setMotionType( hkpMotion::MOTION_FIXED ); HK_SET_OBJECT_COLOR( reinterpret_cast<hkUlong>( bodies[j]->getCollidable() ), hkColor::RED ); m_world->removeEntity( target ); } // A "basic" launchpad just applies a force in the direction of the collision normal else if( rbName.beginsWith( "launchPadBasic" ) ) { LaunchPadListener* launchPadListener = new LaunchPadListener( bodies[j]->getMass() ); bodies[j]->addCollisionListener( launchPadListener ); bodies[j]->setMotionType( hkpMotion::MOTION_FIXED ); HK_SET_OBJECT_COLOR( reinterpret_cast<hkUlong>( bodies[j]->getCollidable() ), hkColor::RED ); } else if( rbName.beginsWith( "teleporterSource" ) ) { hkString targetName; // Find the teleportation destination of the teleporter targetName.printf( "teleporterTarget%s", rbName.substr( hkString::strLen("teleporterSource") ).cString() ); hkpRigidBody* target = m_physicsData->findRigidBodyByName( targetName.cString() ); HK_ASSERT2( 0, target, "All teleporterSource rigid bodies must have associated teleporterTargets." ); // Replace the rb with a callback shape phantom. Colliding rbs will be teleported to the destination. TeleporterPhantomCallbackShape* phantomCallbackShape = new TeleporterPhantomCallbackShape( target->getTransform() ); hkpBvShape* phantom = new hkpBvShape( bodies[j]->getCollidable()->getShape(), phantomCallbackShape ); phantomCallbackShape->removeReference(); bodies[j]->getCollidable()->getShape()->removeReference(); bodies[j]->setShape( phantom ); phantom->removeReference(); m_world->removeEntity( target ); } else if( rbName.beginsWith( "TurretTop" ) ) { // Create a place to store state information for this turret. Turret& turret = m_turrets.expandOne(); turret.constraint = bodies[j]->getConstraint(0); turret.hinge = static_cast<hkpLimitedHingeConstraintData*>( const_cast<hkpConstraintData*>( turret.constraint->getData() ) ); turret.turretRigidBody = bodies[j]; turret.cooldown = 0.0f; // Allow the hinge to spin infinitely and start the motor up turret.hinge->disableLimits(); turret.hinge->setMotorActive( turret.constraint, true ); // Do not allow the turret's simulation island deactivate. // If it does, it will stop spinning. turret.turretRigidBody->setDeactivator( hkpRigidBodyDeactivator::DEACTIVATOR_NEVER ); } // Update collision filter so that needless CollColl3 agents are not created. // For example, turrets and geometry marked as "static" (such as the swing) // should never collide with a planet, nor each other. if( ( rbName.beginsWith( "planet" ) && !rbName.endsWith( "GravField" ) ) || rbName.beginsWith( "Turret" ) || rbName.endsWith( "_static" ) ) { bodies[j]->setCollisionFilterInfo( hkpGroupFilter::calcFilterInfo( 1 ) ); // Destroy or create agents (according to new quality type). This also removes Toi events. m_world->updateCollisionFilterOnEntity(bodies[j], HK_UPDATE_FILTER_ON_ENTITY_FULL_CHECK, HK_UPDATE_COLLECTION_FILTER_PROCESS_SHAPE_COLLECTIONS); } } } m_world->unmarkForWrite(); } }
World::World(QString const & fileName, QObject * parent) : QObject(parent) { init(); loadWorld(fileName); }
World SaveManager::loadWorld(QString savingPath) { World world; loadWorld(savingPath,&world); return world; }