Intro::Intro(Graphics::Renderer *r, int width, int height) : Cutscene(r, width, height) { using Graphics::Light; m_background.reset(new Background::Container(r, UNIVERSE_SEED)); m_ambientColor = Color(0); const Color one = Color::WHITE; const Color two = Color(77, 77, 204, 0); m_lights.push_back(Light(Graphics::Light::LIGHT_DIRECTIONAL, vector3f(0.f, 0.3f, 1.f), one, one)); m_lights.push_back(Light(Graphics::Light::LIGHT_DIRECTIONAL, vector3f(0.f, -1.f, 0.f), two, Color::BLACK)); SceneGraph::ModelSkin skin; skin.SetDecal("pioneer"); skin.SetLabel(Lang::PIONEER); for (std::vector<ShipType::Id>::const_iterator i = ShipType::player_ships.begin(); i != ShipType::player_ships.end(); ++i) { SceneGraph::Model *model = Pi::FindModel(ShipType::types[*i].modelName)->MakeInstance(); skin.SetRandomColors(Pi::rng); skin.Apply(model); model->SetThrust(vector3f(0.f, 0.f, -0.6f), vector3f(0.f)); m_models.push_back(model); } PiRngWrapper rng; std::random_shuffle(m_models.begin(), m_models.end(), rng); m_state = STATE_SELECT; m_modelIndex = 0; }
void Ship::Init() { // XXX the animation namespace must match that in LuaConstants // note: this must be set before generating the collision mesh // (which happens in SetModel()) and before rendering GetLmrObjParams().animationNamespace = "ShipAnimation"; GetLmrObjParams().equipment = &m_equipment; const ShipType &stype = GetShipType(); // Dirty hack: Always use gear-down mesh for collision detection // necessary because some ships have non-docking meshes too large for docking float temp = GetLmrObjParams().animValues[ANIM_WHEEL_STATE]; GetLmrObjParams().animValues[ANIM_WHEEL_STATE] = 1.0f; SetModel(stype.lmrModelName.c_str()); GetLmrObjParams().animValues[ANIM_WHEEL_STATE] = temp; SetMassDistributionFromModel(); UpdateStats(); m_stats.hull_mass_left = float(stype.hullMass); m_stats.shield_mass_left = 0; m_hyperspace.now = false; // TODO: move this on next savegame change, maybe m_hyperspaceCloud = 0; m_landingGearAnimation = 0; SceneGraph::Model *nmodel = dynamic_cast<SceneGraph::Model*>(GetModel()); if (nmodel) { m_landingGearAnimation = nmodel->FindAnimation("gear_down"); } }
void Ship::InitMaterials() { SceneGraph::Model *pModel = GetModel(); assert(pModel); const Uint32 numMats = pModel->GetNumMaterials(); for( Uint32 m=0; m<numMats; m++ ) { RefCountedPtr<Graphics::Material> mat = pModel->GetMaterialByIndex(m); mat->heatGradient = Graphics::TextureBuilder::Decal("textures/heat_gradient.dds").GetOrCreateTexture(Pi::renderer, "model"); mat->specialParameter0 = &s_heatGradientParams; } s_heatGradientParams.heatingAmount = 0.0f; s_heatGradientParams.heatingNormal = vector3f(0.0f, -1.0f, 0.0f); }
/* * Method: SetPattern * * Changes the pattern used for texturing the ship. * * > ship:SetPattern(num) * * Parameters: * * num - the pattern number * * Example: * * > ship:SetPattern(5) * * Status: * * experimental */ static int l_ship_set_pattern(lua_State *l) { Ship *s = LuaObject<Ship>::CheckFromLua(1); unsigned int num = lua_tointeger(l, 2); SceneGraph::Model *model = s->GetModel(); if(model && model->SupportsPatterns()) { if (num > model->GetNumPatterns()-1) return luaL_error(l, "This pattern does not exist for this ship"); s->SetPattern(num); } return 0; }
void SpaceStation::InitStation() { m_adjacentCity = 0; for(int i=0; i<NUM_STATIC_SLOTS; i++) m_staticSlot[i] = false; Random rand(m_sbody->GetSeed()); const bool ground = m_sbody->GetType() == SystemBody::TYPE_STARPORT_ORBITAL ? false : true; m_type = SpaceStationType::RandomStationType(rand, ground); if(m_shipDocking.empty()) { m_shipDocking.reserve(m_type->NumDockingPorts()); for (unsigned int i=0; i<m_type->NumDockingPorts(); i++) { m_shipDocking.push_back(shipDocking_t()); } // only (re)set these if we've not come from the ::Load method m_doorAnimationStep = m_doorAnimationState = 0.0; } assert(m_shipDocking.size() == m_type->NumDockingPorts()); // This SpaceStation's bay ports are an instance of... m_ports = m_type->Ports(); SetStatic(ground); // orbital stations are dynamic now // XXX hack. if we loaded a game then ModelBody::Load already restored the // model and we shouldn't overwrite it if (!GetModel()) SetModel(m_type->ModelName().c_str()); SceneGraph::Model *model = GetModel(); m_navLights.reset(new NavLights(model, 2.2f)); m_navLights->SetEnabled(true); if (ground) SetClipRadius(CITY_ON_PLANET_RADIUS); // overrides setmodel m_doorAnimation = model->FindAnimation("doors"); SceneGraph::ModelSkin skin; skin.SetDecal("pioneer"); if (model->SupportsPatterns()) { skin.SetRandomColors(rand); skin.Apply(model); model->SetPattern(rand.Int32(0, model->GetNumPatterns())); } else { skin.Apply(model); } }
Intro::Intro(Graphics::Renderer *r, int width, int height) : Cutscene(r, width, height) { using Graphics::Light; m_background.reset(new Background::Container(r, Pi::rng)); m_ambientColor = Color::BLANK; const Color one = Color::WHITE; const Color two = Color(77, 77, 204, 0); m_lights.push_back(Light(Graphics::Light::LIGHT_DIRECTIONAL, vector3f(0.f, 0.3f, 1.f), one, one)); m_lights.push_back(Light(Graphics::Light::LIGHT_DIRECTIONAL, vector3f(0.f, -1.f, 0.f), two, Color::BLACK)); m_skin.SetDecal("pioneer"); m_skin.SetLabel(Lang::PIONEER); for (auto i : ShipType::player_ships) { SceneGraph::Model *model = Pi::FindModel(ShipType::types[i].modelName)->MakeInstance(); model->SetThrust(vector3f(0.f, 0.f, -0.6f), vector3f(0.f)); const Uint32 numMats = model->GetNumMaterials(); for( Uint32 m=0; m<numMats; m++ ) { RefCountedPtr<Graphics::Material> mat = model->GetMaterialByIndex(m); mat->specialParameter0 = nullptr; } m_models.push_back(model); } PiRngWrapper rng; std::random_shuffle(m_models.begin(), m_models.end(), rng); m_modelIndex = 0; const int w = Graphics::GetScreenWidth(); const int h = Graphics::GetScreenHeight(); // double-width viewport, centred, then offset 1/6th to centre on the left // 2/3rds of the screen, to the left of the menu m_spinnerLeft = int(float(w)*-.5f - float(w)/6.f); m_spinnerWidth = w*2; m_spinnerRatio = w*2.f/h; m_needReset = true; }
void OnInitialize() { m_debug = false; m_debugGBuffer = false; m_debugCompositing = false; // Camera Setup m_Camera = new CameraFPS(Math::TVector3F(3,4,2), Math::TVector3F(0,0,0)); m_Camera->SetSpeed(10.0); // Initialise OpenGL GLCheck(glClearColor(0.0f,0.0f,0.0f,1.f)); SettingsManager.SetProjection(0.1,100.0,70.0); // Load shader m_GBufferShader = CShaderManager::Instance().LoadShader("GBuffer.shader"); m_RSMSpotShader = CShaderManager::Instance().LoadShader("RefectiveShadowMapSpot.shader"); m_RSMCompositing = CShaderManager::Instance().LoadShader("RefectiveShadowMapCompositing.shader"); // Create light m_light.LightColor = Color(1.0,1.0,1.0,0.0); m_light.Position = Math::TVector3F(0,10.0/3.0,6.0); m_light.LightRaduis = 100.0; m_light.LightIntensity = 1.0; m_light.LightCutOff = 50; m_light.Direction = Math::TVector3F(0.0,-0.6,-1.4); m_light.Direction.Normalize(); // Load scene // * Lucy loading SceneGraph::AssimpNode* lucyModel = SceneGraph::AssimpNode::LoadFromFile("uv_lucy.ply"); SceneGraph::Model* lucyMesh = (SceneGraph::Model*)lucyModel->GetChilds()[0]; Math::CMatrix4 lucyModelMatrix; lucyModelMatrix.SetScaling(1.0,1.0,1.0); lucyModel->LoadTransformMatrix(lucyModelMatrix); RootSceneGraph.AddChild(lucyModel); lucyMesh->AddTextureMap(DIFFUSE_TEXTURE, Texture::LoadFromFile("marble.jpg")); // * Scene loading SceneGraph::AssimpNode* sceneModel = SceneGraph::AssimpNode::LoadFromFile("uv_room.ply"); SceneGraph::Model* sceneMesh = (SceneGraph::Model*)sceneModel->GetChilds()[0]; sceneMesh->AddTextureMap(DIFFUSE_TEXTURE, Texture::LoadFromFile("bricks2_color.jpg")); Math::CMatrix4 sceneModelMatrix; sceneModelMatrix.SetScaling(5.0/3.0,5.0/3.0,5.0/3.0); sceneModel->LoadTransformMatrix(sceneModelMatrix); RootSceneGraph.AddChild(sceneModel); // Generate the texture GenerateRandomTexture(256); }
//static void CityOnPlanet::SetCityModelPatterns(const SystemPath &path) { Uint32 _init[5] = { path.systemIndex, Uint32(path.sectorX), Uint32(path.sectorY), Uint32(path.sectorZ), UNIVERSE_SEED }; Random rand(_init, 5); typedef std::set<SceneGraph::Model*, ModelNameComparator> ModelSet; typedef ModelSet::iterator TSetIter; ModelSet modelSet; { for (unsigned int j=0; j < s_buildingList.numBuildings; j++) { SceneGraph::Model *m = s_buildingList.buildings[j].resolvedModel; modelSet.insert(m); } } SceneGraph::ModelSkin skin; for (TSetIter it=modelSet.begin(), itEnd=modelSet.end(); it!=itEnd; ++it) { SceneGraph::Model *m = (*it); if (!m->SupportsPatterns()) continue; skin.SetRandomColors(rand); skin.Apply(m); m->SetPattern(rand.Int32(0, m->GetNumPatterns())); } }
void Pi::Init(const std::map<std::string,std::string> &options, bool no_gui) { #ifdef PIONEER_PROFILER Profiler::reset(); #endif Profiler::Timer timer; timer.Start(); OS::EnableBreakpad(); OS::NotifyLoadBegin(); FileSystem::Init(); FileSystem::userFiles.MakeDirectory(""); // ensure the config directory exists #ifdef PIONEER_PROFILER FileSystem::userFiles.MakeDirectory("profiler"); profilerPath = FileSystem::JoinPathBelow(FileSystem::userFiles.GetRoot(), "profiler"); #endif Pi::config = new GameConfig(options); if (config->Int("RedirectStdio")) OS::RedirectStdio(); std::string version(PIONEER_VERSION); if (strlen(PIONEER_EXTRAVERSION)) version += " (" PIONEER_EXTRAVERSION ")"; const char* platformName = SDL_GetPlatform(); if(platformName) Output("ver %s on: %s\n\n", version.c_str(), platformName); else Output("ver %s but could not detect platform name.\n\n", version.c_str()); Output("%s\n", OS::GetOSInfoString().c_str()); ModManager::Init(); Lang::Resource res(Lang::GetResource("core", config->String("Lang"))); Lang::MakeCore(res); Pi::detail.planets = config->Int("DetailPlanets"); Pi::detail.textures = config->Int("Textures"); Pi::detail.fracmult = config->Int("FractalMultiple"); Pi::detail.cities = config->Int("DetailCities"); // Initialize SDL Uint32 sdlInitFlags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK; #if defined(DEBUG) || defined(_DEBUG) sdlInitFlags |= SDL_INIT_NOPARACHUTE; #endif if (SDL_Init(sdlInitFlags) < 0) { Error("SDL initialization failed: %s\n", SDL_GetError()); } SDL_version ver; SDL_GetVersion(&ver); Output("SDL Version %d.%d.%d\n", ver.major, ver.minor, ver.patch); Graphics::RendererOGL::RegisterRenderer(); // Do rest of SDL video initialization and create Renderer Graphics::Settings videoSettings = {}; videoSettings.rendererType = Graphics::RENDERER_OPENGL; videoSettings.width = config->Int("ScrWidth"); videoSettings.height = config->Int("ScrHeight"); videoSettings.fullscreen = (config->Int("StartFullscreen") != 0); videoSettings.hidden = no_gui; videoSettings.requestedSamples = config->Int("AntiAliasingMode"); videoSettings.vsync = (config->Int("VSync") != 0); videoSettings.useTextureCompression = (config->Int("UseTextureCompression") != 0); videoSettings.enableDebugMessages = (config->Int("EnableGLDebug") != 0); videoSettings.iconFile = OS::GetIconFilename(); videoSettings.title = "Pioneer"; Pi::renderer = Graphics::Init(videoSettings); Pi::CreateRenderTarget(videoSettings.width, videoSettings.height); Pi::rng.IncRefCount(); // so nothing tries to free it Pi::rng.seed(time(0)); InitJoysticks(); // we can only do bindings once joysticks are initialised. if (!no_gui) // This re-saves the config file. With no GUI we want to allow multiple instances in parallel. KeyBindings::InitBindings(); joystickEnabled = (config->Int("EnableJoystick")) ? true : false; mouseYInvert = (config->Int("InvertMouseY")) ? true : false; compactScanner = (config->Int("CompactScanner")) ? true : false; navTunnelDisplayed = (config->Int("DisplayNavTunnel")) ? true : false; speedLinesDisplayed = (config->Int("SpeedLines")) ? true : false; hudTrailsDisplayed = (config->Int("HudTrails")) ? true : false; EnumStrings::Init(); // get threads up Uint32 numThreads = config->Int("WorkerThreads"); const int numCores = OS::GetNumCores(); assert(numCores > 0); if (numThreads == 0) numThreads = std::max(Uint32(numCores) - 1, 1U); asyncJobQueue.reset(new AsyncJobQueue(numThreads)); Output("started %d worker threads\n", numThreads); syncJobQueue.reset(new SyncJobQueue); Output("ShipType::Init()\n"); // XXX early, Lua init needs it ShipType::Init(); // XXX UI requires Lua but Pi::ui must exist before we start loading // templates. so now we have crap everywhere :/ Output("Lua::Init()\n"); Lua::Init(); Pi::ui.Reset(new UI::Context(Lua::manager, Pi::renderer, Graphics::GetScreenWidth(), Graphics::GetScreenHeight())); LuaInit(); // Gui::Init shouldn't initialise any VBOs, since we haven't tested // that the capability exists. (Gui does not use VBOs so far) Gui::Init(renderer, Graphics::GetScreenWidth(), Graphics::GetScreenHeight(), 800, 600); UI::Box *box = Pi::ui->VBox(5); UI::Label *label = Pi::ui->Label(""); label->SetFont(UI::Widget::FONT_HEADING_NORMAL); UI::Gauge *gauge = Pi::ui->Gauge(); Pi::ui->GetTopLayer()->SetInnerWidget( Pi::ui->Margin(10, UI::Margin::HORIZONTAL)->SetInnerWidget( Pi::ui->Expand()->SetInnerWidget( Pi::ui->Align(UI::Align::MIDDLE)->SetInnerWidget( box->PackEnd(UI::WidgetSet( label, gauge )) ) ) ) ); draw_progress(gauge, label, 0.0f); Output("GalaxyGenerator::Init()\n"); if (config->HasEntry("GalaxyGenerator")) GalaxyGenerator::Init(config->String("GalaxyGenerator"), config->Int("GalaxyGeneratorVersion", GalaxyGenerator::LAST_VERSION)); else GalaxyGenerator::Init(); draw_progress(gauge, label, 0.1f); Output("FaceParts::Init()\n"); FaceParts::Init(); draw_progress(gauge, label, 0.2f); Output("new ModelCache\n"); modelCache = new ModelCache(Pi::renderer); draw_progress(gauge, label, 0.3f); Output("Shields::Init\n"); Shields::Init(Pi::renderer); draw_progress(gauge, label, 0.4f); //unsigned int control_word; //_clearfp(); //_controlfp_s(&control_word, _EM_INEXACT | _EM_UNDERFLOW | _EM_ZERODIVIDE, _MCW_EM); //double fpexcept = Pi::timeAccelRates[1] / Pi::timeAccelRates[0]; Output("BaseSphere::Init\n"); BaseSphere::Init(); draw_progress(gauge, label, 0.5f); Output("CityOnPlanet::Init\n"); CityOnPlanet::Init(); draw_progress(gauge, label, 0.6f); Output("SpaceStation::Init\n"); SpaceStation::Init(); draw_progress(gauge, label, 0.7f); Output("NavLights::Init\n"); NavLights::Init(Pi::renderer); draw_progress(gauge, label, 0.75f); Output("Sfx::Init\n"); Sfx::Init(Pi::renderer); draw_progress(gauge, label, 0.8f); if (!no_gui && !config->Int("DisableSound")) { Output("Sound::Init\n"); Sound::Init(); Sound::SetMasterVolume(config->Float("MasterVolume")); Sound::SetSfxVolume(config->Float("SfxVolume")); GetMusicPlayer().SetVolume(config->Float("MusicVolume")); Sound::Pause(0); if (config->Int("MasterMuted")) Sound::Pause(1); if (config->Int("SfxMuted")) Sound::SetSfxVolume(0.f); if (config->Int("MusicMuted")) GetMusicPlayer().SetEnabled(false); } draw_progress(gauge, label, 0.9f); OS::NotifyLoadEnd(); draw_progress(gauge, label, 1.0f); #if 0 // frame test code Frame *root = new Frame(0, "root", 0); Frame *p1 = new Frame(root, "p1", Frame::FLAG_HAS_ROT); Frame *p1r = new Frame(p1, "p1r", Frame::FLAG_ROTATING); Frame *m1 = new Frame(p1, "m1", Frame::FLAG_HAS_ROT); Frame *m1r = new Frame(m1, "m1r", Frame::FLAG_ROTATING); Frame *p2 = new Frame(root, "p2", Frame::FLAG_HAS_ROT); Frame *p2r = new Frame(p2, "pr2", Frame::FLAG_ROTATING); p1->SetPosition(vector3d(1000,0,0)); p1->SetVelocity(vector3d(0,1,0)); p2->SetPosition(vector3d(0,2000,0)); p2->SetVelocity(vector3d(-2,0,0)); p1r->SetAngVelocity(vector3d(0,0,0.0001)); p1r->SetOrient(matrix3x3d::BuildRotate(M_PI/4, vector3d(0,0,1))); p2r->SetAngVelocity(vector3d(0,0,-0.0004)); p2r->SetOrient(matrix3x3d::BuildRotate(-M_PI/2, vector3d(0,0,1))); root->UpdateOrbitRails(0, 0); CargoBody *c1 = new CargoBody(Equip::Type::SLAVES); c1->SetFrame(p1r); c1->SetPosition(vector3d(0,180,0)); // c1->SetVelocity(vector3d(1,0,0)); CargoBody *c2 = new CargoBody(Equip::Type::SLAVES); c2->SetFrame(p1r); c2->SetPosition(vector3d(0,200,0)); // c2->SetVelocity(vector3d(1,0,0)); vector3d pos = c1->GetPositionRelTo(p1); vector3d vel = c1->GetVelocityRelTo(p1); double speed = vel.Length(); vector3d pos2 = c2->GetPositionRelTo(p1); vector3d vel2 = c2->GetVelocityRelTo(p1); double speed2 = vel2.Length(); double speed3 = c2->GetVelocityRelTo(c1).Length(); c2->SwitchToFrame(p1); vector3d vel4 = c2->GetVelocityRelTo(c1); double speed4 = c2->GetVelocityRelTo(c1).Length(); root->UpdateOrbitRails(0, 1.0); //buildrotate test matrix3x3d m = matrix3x3d::BuildRotate(M_PI/2, vector3d(0,0,1)); vector3d v = m * vector3d(1,0,0); /* vector3d pos = p1r->GetPositionRelTo(p2r); vector3d vel = p1r->GetVelocityRelTo(p2r); matrix3x3d o1 = p1r->GetOrientRelTo(p2r); double speed = vel.Length(); vector3d pos2 = p2r->GetPositionRelTo(p1r); vector3d vel2 = p2r->GetVelocityRelTo(p1r); matrix3x3d o2 = p2r->GetOrientRelTo(p1r); double speed2 = vel2.Length(); */ root->UpdateOrbitRails(0, 1.0/60); delete p2r; delete p2; delete m1r; delete m1; delete p1r; delete p1; delete root; delete c1; delete c2; #endif #if 0 // test code to produce list of ship stats FILE *pStatFile = fopen("shipstat.csv","wt"); if (pStatFile) { fprintf(pStatFile, "name,modelname,hullmass,capacity,fakevol,rescale,xsize,ysize,zsize,facc,racc,uacc,sacc,aacc,exvel\n"); for (auto iter : ShipType::types) { const ShipType *shipdef = &(iter.second); SceneGraph::Model *model = Pi::FindModel(shipdef->modelName, false); double hullmass = shipdef->hullMass; double capacity = shipdef->capacity; double xsize = 0.0, ysize = 0.0, zsize = 0.0, fakevol = 0.0, rescale = 0.0, brad = 0.0; if (model) { std::unique_ptr<SceneGraph::Model> inst(model->MakeInstance()); model->CreateCollisionMesh(); Aabb aabb = model->GetCollisionMesh()->GetAabb(); xsize = aabb.max.x-aabb.min.x; ysize = aabb.max.y-aabb.min.y; zsize = aabb.max.z-aabb.min.z; fakevol = xsize*ysize*zsize; brad = aabb.GetRadius(); rescale = pow(fakevol/(100 * (hullmass+capacity)), 0.3333333333); } double simass = (hullmass + capacity) * 1000.0; double angInertia = (2/5.0)*simass*brad*brad; double acc1 = shipdef->linThrust[ShipType::THRUSTER_FORWARD] / (9.81*simass); double acc2 = shipdef->linThrust[ShipType::THRUSTER_REVERSE] / (9.81*simass); double acc3 = shipdef->linThrust[ShipType::THRUSTER_UP] / (9.81*simass); double acc4 = shipdef->linThrust[ShipType::THRUSTER_RIGHT] / (9.81*simass); double acca = shipdef->angThrust/angInertia; double exvel = shipdef->effectiveExhaustVelocity; fprintf(pStatFile, "%s,%s,%.1f,%.1f,%.1f,%.3f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%f,%.1f\n", shipdef->name.c_str(), shipdef->modelName.c_str(), hullmass, capacity, fakevol, rescale, xsize, ysize, zsize, acc1, acc2, acc3, acc4, acca, exvel); } fclose(pStatFile); } #endif luaConsole = new LuaConsole(); KeyBindings::toggleLuaConsole.onPress.connect(sigc::mem_fun(Pi::luaConsole, &LuaConsole::Toggle)); planner = new TransferPlanner(); timer.Stop(); Output("\n\nLoading took: %lf milliseconds\n", timer.millicycles()); }
void Pi::Init() { OS::NotifyLoadBegin(); FileSystem::Init(); FileSystem::userFiles.MakeDirectory(""); // ensure the config directory exists Pi::config = new GameConfig(); KeyBindings::InitBindings(); if (config->Int("RedirectStdio")) OS::RedirectStdio(); ModManager::Init(); if (!Lang::LoadStrings(config->String("Lang"))) abort(); Pi::detail.planets = config->Int("DetailPlanets"); Pi::detail.textures = config->Int("Textures"); Pi::detail.fracmult = config->Int("FractalMultiple"); Pi::detail.cities = config->Int("DetailCities"); #ifdef __linux__ // there appears to be a bug in the Linux evdev input driver that stops // DGA mouse grab restoring state correctly. SDL can use an alternative // method, but its only configurable via environment variable. Here we set // that environment variable (unless the user explicitly doesn't want it // via config). // // we also enable warp-after-grab here, as the SDL alternative method // doesn't restore the mouse pointer to its pre-grab position // // XXX SDL2 uses a different mechanism entirely and this environment // variable doesn't exist there, so we can get rid of it when we go to SDL2 if (!config->Int("SDLUseDGAMouse")) { Pi::warpAfterMouseGrab = true; setenv("SDL_VIDEO_X11_DGAMOUSE", "0", 1); } #endif // Initialize SDL Uint32 sdlInitFlags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK; #if defined(DEBUG) || defined(_DEBUG) sdlInitFlags |= SDL_INIT_NOPARACHUTE; #endif if (SDL_Init(sdlInitFlags) < 0) { OS::Error("SDL initialization failed: %s\n", SDL_GetError()); } // needed for the UI SDL_EnableUNICODE(1); // Do rest of SDL video initialization and create Renderer Graphics::Settings videoSettings = {}; videoSettings.width = config->Int("ScrWidth"); videoSettings.height = config->Int("ScrHeight"); videoSettings.fullscreen = (config->Int("StartFullscreen") != 0); videoSettings.shaders = (config->Int("DisableShaders") == 0); videoSettings.requestedSamples = config->Int("AntiAliasingMode"); videoSettings.vsync = (config->Int("VSync") != 0); videoSettings.useTextureCompression = (config->Int("UseTextureCompression") != 0); Pi::renderer = Graphics::Init(videoSettings); { std::ostringstream buf; renderer->PrintDebugInfo(buf); FILE *f = FileSystem::userFiles.OpenWriteStream("opengl.txt", FileSystem::FileSourceFS::WRITE_TEXT); if (!f) fprintf(stderr, "Could not open 'opengl.txt'\n"); const std::string &s = buf.str(); fwrite(s.c_str(), 1, s.size(), f); fclose(f); } OS::LoadWindowIcon(); SDL_WM_SetCaption("Pioneer","Pioneer"); Pi::scrAspect = videoSettings.width / float(videoSettings.height); Pi::rng.IncRefCount(); // so nothing tries to free it Pi::rng.seed(time(0)); InitJoysticks(); joystickEnabled = (config->Int("EnableJoystick")) ? true : false; mouseYInvert = (config->Int("InvertMouseY")) ? true : false; navTunnelDisplayed = (config->Int("DisplayNavTunnel")) ? true : false; EnumStrings::Init(); // XXX early, Lua init needs it ShipType::Init(); // XXX UI requires Lua but Pi::ui must exist before we start loading // templates. so now we have crap everywhere :/ Lua::Init(); Pi::ui.Reset(new UI::Context(Lua::manager, Pi::renderer, Graphics::GetScreenWidth(), Graphics::GetScreenHeight(), Lang::GetCurrentLanguage())); LuaInit(); // Gui::Init shouldn't initialise any VBOs, since we haven't tested // that the capability exists. (Gui does not use VBOs so far) Gui::Init(renderer, Graphics::GetScreenWidth(), Graphics::GetScreenHeight(), 800, 600); draw_progress(0.1f); Galaxy::Init(); draw_progress(0.2f); Faction::Init(); draw_progress(0.3f); CustomSystem::Init(); draw_progress(0.4f); modelCache = new ModelCache(Pi::renderer); draw_progress(0.5f); //unsigned int control_word; //_clearfp(); //_controlfp_s(&control_word, _EM_INEXACT | _EM_UNDERFLOW | _EM_ZERODIVIDE, _MCW_EM); //double fpexcept = Pi::timeAccelRates[1] / Pi::timeAccelRates[0]; draw_progress(0.6f); GeoSphere::Init(); draw_progress(0.7f); CityOnPlanet::Init(); draw_progress(0.8f); SpaceStation::Init(); draw_progress(0.9f); NavLights::Init(Pi::renderer); Sfx::Init(Pi::renderer); draw_progress(0.95f); if (!config->Int("DisableSound")) { Sound::Init(); Sound::SetMasterVolume(config->Float("MasterVolume")); Sound::SetSfxVolume(config->Float("SfxVolume")); GetMusicPlayer().SetVolume(config->Float("MusicVolume")); Sound::Pause(0); if (config->Int("MasterMuted")) Sound::Pause(1); if (config->Int("SfxMuted")) Sound::SetSfxVolume(0.f); if (config->Int("MusicMuted")) GetMusicPlayer().SetEnabled(false); } draw_progress(1.0f); OS::NotifyLoadEnd(); #if 0 // frame test code Frame *root = new Frame(0, "root", 0); Frame *p1 = new Frame(root, "p1", Frame::FLAG_HAS_ROT); Frame *p1r = new Frame(p1, "p1r", Frame::FLAG_ROTATING); Frame *m1 = new Frame(p1, "m1", Frame::FLAG_HAS_ROT); Frame *m1r = new Frame(m1, "m1r", Frame::FLAG_ROTATING); Frame *p2 = new Frame(root, "p2", Frame::FLAG_HAS_ROT); Frame *p2r = new Frame(p2, "pr2", Frame::FLAG_ROTATING); p1->SetPosition(vector3d(1000,0,0)); p1->SetVelocity(vector3d(0,1,0)); p2->SetPosition(vector3d(0,2000,0)); p2->SetVelocity(vector3d(-2,0,0)); p1r->SetAngVelocity(vector3d(0,0,0.0001)); p1r->SetOrient(matrix3x3d::BuildRotate(M_PI/4, vector3d(0,0,1))); p2r->SetAngVelocity(vector3d(0,0,-0.0004)); p2r->SetOrient(matrix3x3d::BuildRotate(-M_PI/2, vector3d(0,0,1))); root->UpdateOrbitRails(0, 0); CargoBody *c1 = new CargoBody(Equip::Type::SLAVES); c1->SetFrame(p1r); c1->SetPosition(vector3d(0,180,0)); // c1->SetVelocity(vector3d(1,0,0)); CargoBody *c2 = new CargoBody(Equip::Type::SLAVES); c2->SetFrame(p1r); c2->SetPosition(vector3d(0,200,0)); // c2->SetVelocity(vector3d(1,0,0)); vector3d pos = c1->GetPositionRelTo(p1); vector3d vel = c1->GetVelocityRelTo(p1); double speed = vel.Length(); vector3d pos2 = c2->GetPositionRelTo(p1); vector3d vel2 = c2->GetVelocityRelTo(p1); double speed2 = vel2.Length(); double speed3 = c2->GetVelocityRelTo(c1).Length(); c2->SwitchToFrame(p1); vector3d vel4 = c2->GetVelocityRelTo(c1); double speed4 = c2->GetVelocityRelTo(c1).Length(); root->UpdateOrbitRails(0, 1.0); //buildrotate test matrix3x3d m = matrix3x3d::BuildRotate(M_PI/2, vector3d(0,0,1)); vector3d v = m * vector3d(1,0,0); /* vector3d pos = p1r->GetPositionRelTo(p2r); vector3d vel = p1r->GetVelocityRelTo(p2r); matrix3x3d o1 = p1r->GetOrientRelTo(p2r); double speed = vel.Length(); vector3d pos2 = p2r->GetPositionRelTo(p1r); vector3d vel2 = p2r->GetVelocityRelTo(p1r); matrix3x3d o2 = p2r->GetOrientRelTo(p1r); double speed2 = vel2.Length(); */ root->UpdateOrbitRails(0, 1.0/60); delete p2r; delete p2; delete m1r; delete m1; delete p1r; delete p1; delete root; delete c1; delete c2; #endif #if 0 // test code to produce list of ship stats FILE *pStatFile = fopen("shipstat.csv","wt"); if (pStatFile) { fprintf(pStatFile, "name,modelname,hullmass,capacity,fakevol,rescale,xsize,ysize,zsize,facc,racc,uacc,sacc,aacc,exvel\n"); for (std::map<std::string, ShipType>::iterator i = ShipType::types.begin(); i != ShipType::types.end(); ++i) { const ShipType *shipdef = &(i->second); SceneGraph::Model *model = Pi::FindModel(shipdef->modelName, false); double hullmass = shipdef->hullMass; double capacity = shipdef->capacity; double xsize = 0.0, ysize = 0.0, zsize = 0.0, fakevol = 0.0, rescale = 0.0, brad = 0.0; if (model) { ScopedPtr<SceneGraph::Model> inst(model->MakeInstance()); model->CreateCollisionMesh(); Aabb aabb = model->GetCollisionMesh()->GetAabb(); xsize = aabb.max.x-aabb.min.x; ysize = aabb.max.y-aabb.min.y; zsize = aabb.max.z-aabb.min.z; fakevol = xsize*ysize*zsize; brad = aabb.GetRadius(); rescale = pow(fakevol/(100 * (hullmass+capacity)), 0.3333333333); } double simass = (hullmass + capacity) * 1000.0; double angInertia = (2/5.0)*simass*brad*brad; double acc1 = shipdef->linThrust[ShipType::THRUSTER_FORWARD] / (9.81*simass); double acc2 = shipdef->linThrust[ShipType::THRUSTER_REVERSE] / (9.81*simass); double acc3 = shipdef->linThrust[ShipType::THRUSTER_UP] / (9.81*simass); double acc4 = shipdef->linThrust[ShipType::THRUSTER_RIGHT] / (9.81*simass); double acca = shipdef->angThrust/angInertia; double exvel = shipdef->effectiveExhaustVelocity; fprintf(pStatFile, "%s,%s,%.1f,%.1f,%.1f,%.3f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%f,%.1f\n", shipdef->name.c_str(), shipdef->modelName.c_str(), hullmass, capacity, fakevol, rescale, xsize, ysize, zsize, acc1, acc2, acc3, acc4, acca, exvel); } fclose(pStatFile); } #endif luaConsole = new LuaConsole(10); KeyBindings::toggleLuaConsole.onPress.connect(sigc::ptr_fun(&Pi::ToggleLuaConsole)); gameMenuView = new GameMenuView(); config->Save(); }