/* Must be called after LmrModel init is called */ void SpaceStation::Init() { if (stationTypesInitted) return; stationTypesInitted = true; for (int is_orbital=0; is_orbital<2; is_orbital++) { std::vector<LmrModel*> models; if (is_orbital) LmrGetModelsWithTag("orbital_station", models); else LmrGetModelsWithTag("surface_station", models); for (std::vector<LmrModel*>::iterator i = models.begin(); i != models.end(); ++i) { SpaceStationType t; t.modelName = (*i)->GetName(); t.model = LmrLookupModelByName(t.modelName); t.dockMethod = SpaceStationType::DOCKMETHOD(is_orbital); t.numDockingPorts = (*i)->GetIntAttribute("num_docking_ports"); t.dockOneAtATimePlease = (*i)->GetBoolAttribute("dock_one_at_a_time_please"); t.ReadStageDurations(); //printf("one at a time? %s\n", t.dockOneAtATimePlease ? "yes" : "no"); //printf("%s: %d docking ports\n", t.modelName, t.numDockingPorts); if (is_orbital) { t.angVel = (*i)->GetFloatAttribute("angular_velocity"); orbitalStationTypes.push_back(t); } else surfaceStationTypes.push_back(t); } } //printf(SIZET_FMT " orbital station types and " SIZET_FMT " surface station types.\n", orbitalStationTypes.size(), surfaceStationTypes.size()); }
static void draw_tombstone(float _time) { float lightCol[4] = { 1,1,1,0 }; float lightDir[4] = { 0,1,1,0 }; float ambient[4] = { 0.1,0.1,0.1,1 }; LmrObjParams params = { { 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { "RIP OLD BEAN" }, { 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { // pColor[3] { { 1.0f, 1.0f, 1.0f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }, { { 0.8f, 0.6f, 0.5f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }, { { 0.5f, 0.5f, 0.5f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 } }, }; glPushAttrib(GL_ALL_ATTRIB_BITS); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_POSITION, lightDir); glLightfv(GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, lightCol); glLightfv(GL_LIGHT0, GL_SPECULAR, lightCol); glEnable(GL_LIGHT0); matrix4x4f rot = matrix4x4f::RotateYMatrix(_time*2); rot[14] = -std::max(150.0f - 30.0f*_time, 30.0f); LmrLookupModelByName("tombstone")->Render(rot, ¶ms); Render::State::UseProgram(0); Render::UnbindAllBuffers(); glPopAttrib(); }
Tombstone::Tombstone(Graphics::Renderer *r, int width, int height) : Cutscene(r, width, height) { m_ambientColor = Color(0.1f, 0.1f, 0.1f, 1.f); const Color lc(1.f, 1.f, 1.f, 0.f); m_lights.push_back(Graphics::Light(Graphics::Light::LIGHT_DIRECTIONAL, vector3f(0.f, 1.f, 1.f), lc, lc, lc)); m_model = LmrLookupModelByName("tombstone"); // Model parameters LmrObjParams params = { 0, // animation namespace 0.0, // time {}, // animation stages {}, // animation positions Lang::TOMBSTONE_EPITAPH, // label 0, // equipment 0, // flightState { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { // pColor[3] { { 1.0f, 1.0f, 1.0f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }, { { 0.8f, 0.6f, 0.5f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }, { { 0.5f, 0.5f, 0.5f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 } }, }; m_modelParams = params; }
ShipSpinnerWidget::ShipSpinnerWidget(const ShipFlavour &flavour, float width, float height) : m_width(width), m_height(height) { m_model = LmrLookupModelByName(ShipType::types[flavour.type].lmrModelName.c_str()); memset(&m_params, 0, sizeof(LmrObjParams)); flavour.ApplyTo(&m_params); m_params.argDoubles[0] = 1.0; }
void ModelBody::SetModel(const char *lmrModelName, bool isStatic) { m_isStatic = isStatic; try { m_lmrModel = LmrLookupModelByName(lmrModelName); } catch (LmrModelNotFoundException) { printf("Could not find model '%s'.\n", lmrModelName); Pi::Quit(); } RebuildCollisionMesh(); }
void Viewer::TryModel(const SDL_keysym *sym, Gui::TextEntry *entry, Gui::Label *errormsg) { if (sym->sym == SDLK_RETURN) { LmrModel *m = 0; try { m = LmrLookupModelByName(entry->GetText().c_str()); } catch (LmrModelNotFoundException) { errormsg->SetText("Could not find model: " + entry->GetText()); } if (m) SetModel(m); } }
ModelBase *Pi::FindModel(const std::string &name) { // Try NewModel models first, then LMR ModelBase *m = 0; try { m = Pi::modelCache->FindModel(name); } catch (ModelCache::ModelNotFoundException) { try { m = LmrLookupModelByName(name.c_str()); } catch (LmrModelNotFoundException) { Error("Could not find model %s", name.c_str()); } } return m; }
ShipSpinnerWidget::ShipSpinnerWidget(const ShipFlavour &flavour, float width, float height) : m_width(width), m_height(height) { m_model = LmrLookupModelByName(ShipType::types[flavour.type].lmrModelName.c_str()); memset(&m_params, 0, sizeof(LmrObjParams)); m_params.animationNamespace = "ShipAnimation"; m_params.equipment = &m_equipment; flavour.ApplyTo(&m_params); m_params.animValues[Ship::ANIM_WHEEL_STATE] = 1.0; m_params.flightState = Ship::FLYING; Color lc(0.5f, 0.5f, 0.5f, 0.f); m_light.SetDiffuse(lc); m_light.SetAmbient(lc); m_light.SetSpecular(lc); m_light.SetPosition(vector3f(1.f, 1.f, 0.f)); m_light.SetType(Light::LIGHT_DIRECTIONAL); }
Tombstone::Tombstone(Graphics::Renderer *r, int width, int height) : Cutscene(r, width, height) { m_ambientColor = Color(0.1f, 0.1f, 0.1f, 1.f); const Color lc(1.f, 1.f, 1.f, 0.f); m_lights.push_back(Graphics::Light(Graphics::Light::LIGHT_DIRECTIONAL, vector3f(0.f, 1.f, 1.f), lc, lc, lc)); m_model = LmrLookupModelByName("tombstone"); // Model parameters memset(&m_modelParams, 0, sizeof(LmrObjParams)); LmrMaterial matA = { { 1.0f, 1.0f, 1.0f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }; LmrMaterial matB = { { 0.8f, 0.6f, 0.5f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }; LmrMaterial matC = { { 0.5f, 0.5f, 0.5f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }; m_modelParams.pMat[0] = matA; m_modelParams.pMat[1] = matB; m_modelParams.pMat[2] = matC; m_modelParams.label = Lang::TOMBSTONE_EPITAPH; }
ShipSpinner::ShipSpinner(Context *context, const ShipFlavour &flavour) : Widget(context), m_flavour(flavour), m_rotX(0), m_rotY(0) { m_model = LmrLookupModelByName(ShipType::types[m_flavour.id].lmrModelName.c_str()); memset(&m_params, 0, sizeof(LmrObjParams)); m_params.animationNamespace = "ShipAnimation"; m_params.equipment = &m_equipment; m_flavour.ApplyTo(&m_params); m_params.animValues[Ship::ANIM_WHEEL_STATE] = 1.0; m_params.flightState = Ship::FLYING; Color lc(0.5f, 0.5f, 0.5f, 0.f); m_light.SetDiffuse(lc); m_light.SetAmbient(lc); m_light.SetSpecular(lc); m_light.SetPosition(vector3f(1.f, 1.f, 0.f)); m_light.SetType(Graphics::Light::LIGHT_DIRECTIONAL); }
static void draw_intro(WorldView *view, float _time) { float lightCol[4] = { 1,1,1,0 }; float lightDir[4] = { 0,1,1,0 }; float ambient[4] = { 0.1,0.1,0.1,1 }; // defaults are dandy Render::State::SetZnearZfar(1.0f, 10000.0f); LmrObjParams params = { { }, { "PIONEER" }, { 0.0f, 0.0f, -1.0f }, { 0.0f, 0.0f, 0.0f }, { // pColor[3] { { .2f, .2f, .5f, 1.0f }, { 1, 1, 1 }, { 0, 0, 0 }, 100.0 }, { { 0.5f, 0.5f, 0.5f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }, { { 0.8f, 0.8f, 0.8f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 } }, }; glPushMatrix(); glRotatef(_time*10, 1, 0, 0); view->DrawBgStars(); glPopMatrix(); glPushAttrib(GL_ALL_ATTRIB_BITS); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_POSITION, lightDir); glLightfv(GL_LIGHT0, GL_AMBIENT, lightCol); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightCol); glLightfv(GL_LIGHT0, GL_SPECULAR, lightCol); glEnable(GL_LIGHT0); matrix4x4f rot = matrix4x4f::RotateYMatrix(_time) * matrix4x4f::RotateZMatrix(0.6*_time) * matrix4x4f::RotateXMatrix(_time*.7); rot[14] = -80.0; LmrLookupModelByName("lanner_ub")->Render(rot, ¶ms); Render::State::UseProgram(0); Render::UnbindAllBuffers(); glPopAttrib(); }
Intro::Intro(Graphics::Renderer *r, int width, int height) : Cutscene(r, width, height) { m_background.Reset(new Background::Container(r, UNIVERSE_SEED)); m_ambientColor = Color(0.1f, 0.1f, 0.1f, 1.f); const Color lc(1.f, 1.f, 1.f, 0.f); m_lights.push_back(Graphics::Light(Graphics::Light::LIGHT_DIRECTIONAL, vector3f(0.f, 1.f, 1.f), lc, lc, lc)); m_model = LmrLookupModelByName("lanner_ub"); // Model parameters memset(&m_modelParams, 0, sizeof(LmrObjParams)); m_modelParams.animationNamespace = "ShipAnimation"; m_modelParams.label = Lang::PIONEER; m_modelParams.flightState = Ship::FLYING; m_modelParams.linthrust[2] = -1.f; m_modelParams.animValues[1] = 1.f; LmrMaterial matA = { { .2f, .2f, .5f, 1.0f }, { 1, 1, 1 }, { 0, 0, 0 }, 100.0 }; LmrMaterial matB = { { 0.5f, 0.5f, 0.5f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }; LmrMaterial matC = { { 0.8f, 0.8f, 0.8f, 1.0f }, { 0, 0, 0 }, { 0, 0, 0 }, 0 }; m_modelParams.pMat[0] = matA; m_modelParams.pMat[1] = matB; m_modelParams.pMat[2] = matC; // Some equipment (in case the model can show them) m_equipment.Add(Equip::ECM_ADVANCED, 1); m_equipment.Add(Equip::HYPERCLOUD_ANALYZER, 1); m_equipment.Add(Equip::ATMOSPHERIC_SHIELDING, 1); m_equipment.Add(Equip::FUEL_SCOOP, 1); m_equipment.Add(Equip::SCANNER, 1); m_equipment.Add(Equip::RADAR_MAPPER, 1); m_equipment.Add(Equip::MISSILE_NAVAL, 4); m_modelParams.equipment = &m_equipment; }
void Pi::Init() { config.Load(GetPiUserDir() + "config.ini"); Pi::detail.planets = config.Int("DetailPlanets"); Pi::detail.cities = config.Int("DetailCities"); int width = config.Int("ScrWidth"); int height = config.Int("ScrHeight"); const SDL_VideoInfo *info = NULL; Uint32 sdlInitFlags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK; #if defined _WIN32 && defined _DEBUG sdlInitFlags |= SDL_INIT_NOPARACHUTE; #endif if (SDL_Init(sdlInitFlags) < 0) { fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError()); exit(-1); } InitJoysticks(); // no mode set, find an ok one if ((width <= 0) || (height <= 0)) { SDL_Rect **modes = SDL_ListModes(NULL, SDL_HWSURFACE | SDL_FULLSCREEN); if (modes == 0) { fprintf(stderr, "It seems no video modes are available..."); } if (modes == (SDL_Rect **)-1) { // hm. all modes available. odd. try 800x600 width = 800; height = 600; } else { width = modes[0]->w; height = modes[0]->h; } } info = SDL_GetVideoInfo(); printf("SDL_GetVideoInfo says %d bpp\n", info->vfmt->BitsPerPixel); switch (info->vfmt->BitsPerPixel) { case 16: SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); break; case 24: case 32: SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); break; default: fprintf(stderr, "Invalid pixel depth: %d bpp\n", info->vfmt->BitsPerPixel); } SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); Uint32 flags = SDL_OPENGL; if (config.Int("StartFullscreen")) flags |= SDL_FULLSCREEN; if ((Pi::scrSurface = SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, flags)) == 0) { // fall back on 16-bit depth buffer... SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); fprintf(stderr, "Failed to set video mode. (%s). Re-trying with 16-bit depth buffer.\n", SDL_GetError()); if ((Pi::scrSurface = SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, flags)) == 0) { fprintf(stderr, "Failed to set video mode: %s", SDL_GetError()); } } glewInit(); SDL_WM_SetCaption("Pioneer","Pioneer"); Pi::scrWidth = width; Pi::scrHeight = height; Pi::scrAspect = width / (float)height; Pi::rng.seed(time(NULL)); InitOpenGL(); GLFTInit(); // 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(scrWidth, scrHeight, 800, 600); if (!GLEW_ARB_vertex_buffer_object) { Error("OpenGL extension ARB_vertex_buffer_object not supported. Pioneer can not run on your graphics card."); } Render::Init(width, height); draw_progress(0.1f); Galaxy::Init(); draw_progress(0.2f); NameGenerator::Init(); if (config.Int("DisableShaders")) Render::ToggleShaders(); if (config.Int("EnableHDR")) Render::ToggleHDR(); draw_progress(0.3f); LmrModelCompilerInit(); //unsigned int control_word; //_clearfp(); //_controlfp_s(&control_word, _EM_INEXACT | _EM_UNDERFLOW, _MCW_EM); //double fpexcept = Pi::timeAccelRates[1] / Pi::timeAccelRates[0]; draw_progress(0.4f); ShipType::Init(); draw_progress(0.5f); GeoSphere::Init(); draw_progress(0.6f); Space::Init(); draw_progress(0.7f); Polit::Init(); draw_progress(0.8f); SpaceStation::Init(); draw_progress(0.9f); if (!config.Int("DisableSound")) { Sound::Init(); Sound::SetGlobalVolume(config.Float("SfxVolume")); Sound::Pause(0); } draw_progress(1.0f); // test code to produce list of ship stats FILE *pStatFile = fopen("shipstat.csv","wt"); if (pStatFile) { fprintf(pStatFile, "name,lmrname,hullmass,capacity,xsize,ysize,zsize,facc,racc,uacc,aacc\n"); for (std::map<std::string, ShipType>::iterator i = ShipType::types.begin(); i != ShipType::types.end(); ++i) { ShipType *shipdef = &(i->second); LmrModel *lmrModel = LmrLookupModelByName(shipdef->lmrModelName.c_str()); LmrObjParams lmrParams; memset(&lmrParams, 0, sizeof(LmrObjParams)); LmrCollMesh *collMesh = new LmrCollMesh(lmrModel, &lmrParams); Aabb aabb = collMesh->GetAabb(); double hullmass = shipdef->hullMass; double capacity = shipdef->capacity; double xsize = aabb.max.x-aabb.min.x; double ysize = aabb.max.y-aabb.min.y; double zsize = aabb.max.z-aabb.min.z; double brad = aabb.GetBoundingRadius(); 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 acca = shipdef->angThrust/angInertia; fprintf(pStatFile, "%s,%s,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%f\n", shipdef->name.c_str(), shipdef->lmrModelName.c_str(), hullmass, capacity, xsize, ysize, zsize, acc1, acc2, acc3, acca); } fclose(pStatFile); } gameMenuView = new GameMenuView(); config.Save(); }
int _define_ship(lua_State *L, ShipType::Tag tag, std::vector<ShipType::Type> *list) { if (s_currentShipFile.empty()) return luaL_error(L, "ship file contains multiple ship definitions"); ShipType s; s.tag = tag; LUA_DEBUG_START(L); _get_string_attrib(L, "name", s.name, ""); _get_string_attrib(L, "model", s.lmrModelName, ""); _get_float_attrib(L, "reverse_thrust", s.linThrust[ShipType::THRUSTER_REVERSE], 0.0f); _get_float_attrib(L, "forward_thrust", s.linThrust[ShipType::THRUSTER_FORWARD], 0.0f); _get_float_attrib(L, "up_thrust", s.linThrust[ShipType::THRUSTER_UP], 0.0f); _get_float_attrib(L, "down_thrust", s.linThrust[ShipType::THRUSTER_DOWN], 0.0f); _get_float_attrib(L, "left_thrust", s.linThrust[ShipType::THRUSTER_LEFT], 0.0f); _get_float_attrib(L, "right_thrust", s.linThrust[ShipType::THRUSTER_RIGHT], 0.0f); _get_float_attrib(L, "angular_thrust", s.angThrust, 0.0f); // invert values where necessary s.linThrust[ShipType::THRUSTER_FORWARD] *= -1.f; s.linThrust[ShipType::THRUSTER_LEFT] *= -1.f; s.linThrust[ShipType::THRUSTER_DOWN] *= -1.f; // angthrust fudge (XXX: why?) s.angThrust = s.angThrust / 2; _get_vec_attrib(L, "camera_offset", s.cameraOffset, vector3d(0.0)); for (int i=0; i<Equip::SLOT_MAX; i++) s.equipSlotCapacity[i] = 0; _get_int_attrib(L, "max_cargo", s.equipSlotCapacity[Equip::SLOT_CARGO], 0); _get_int_attrib(L, "max_engine", s.equipSlotCapacity[Equip::SLOT_ENGINE], 1); _get_int_attrib(L, "max_laser", s.equipSlotCapacity[Equip::SLOT_LASER], 1); _get_int_attrib(L, "max_missile", s.equipSlotCapacity[Equip::SLOT_MISSILE], 0); _get_int_attrib(L, "max_ecm", s.equipSlotCapacity[Equip::SLOT_ECM], 1); _get_int_attrib(L, "max_scanner", s.equipSlotCapacity[Equip::SLOT_SCANNER], 1); _get_int_attrib(L, "max_radarmapper", s.equipSlotCapacity[Equip::SLOT_RADARMAPPER], 1); _get_int_attrib(L, "max_hypercloud", s.equipSlotCapacity[Equip::SLOT_HYPERCLOUD], 1); _get_int_attrib(L, "max_hullautorepair", s.equipSlotCapacity[Equip::SLOT_HULLAUTOREPAIR], 1); _get_int_attrib(L, "max_energybooster", s.equipSlotCapacity[Equip::SLOT_ENERGYBOOSTER], 1); _get_int_attrib(L, "max_atmoshield", s.equipSlotCapacity[Equip::SLOT_ATMOSHIELD], 1); _get_int_attrib(L, "max_cabin", s.equipSlotCapacity[Equip::SLOT_CABIN], 50); _get_int_attrib(L, "max_shield", s.equipSlotCapacity[Equip::SLOT_SHIELD], 9999); _get_int_attrib(L, "max_fuelscoop", s.equipSlotCapacity[Equip::SLOT_FUELSCOOP], 1); _get_int_attrib(L, "max_cargoscoop", s.equipSlotCapacity[Equip::SLOT_CARGOSCOOP], 1); _get_int_attrib(L, "max_lasercooler", s.equipSlotCapacity[Equip::SLOT_LASERCOOLER], 1); _get_int_attrib(L, "max_cargolifesupport", s.equipSlotCapacity[Equip::SLOT_CARGOLIFESUPPORT], 1); _get_int_attrib(L, "max_autopilot", s.equipSlotCapacity[Equip::SLOT_AUTOPILOT], 1); _get_int_attrib(L, "capacity", s.capacity, 0); _get_int_attrib(L, "hull_mass", s.hullMass, 100); _get_int_attrib(L, "fuel_tank_mass", s.fuelTankMass, 5); _get_float_attrib(L, "thruster_fuel_use", s.thrusterFuelUse, 1.f); _get_int_attrib(L, "price", s.baseprice, 0); s.baseprice *= 100; // in hundredths of credits s.equipSlotCapacity[Equip::SLOT_ENGINE] = Clamp(s.equipSlotCapacity[Equip::SLOT_ENGINE], 0, 1); { int hyperclass; _get_int_attrib(L, "hyperdrive_class", hyperclass, 1); if (!hyperclass) { s.hyperdrive = Equip::NONE; } else { s.hyperdrive = Equip::Type(Equip::DRIVE_CLASS1+hyperclass-1); } } lua_pushstring(L, "gun_mounts"); lua_gettable(L, -2); if (lua_istable(L, -1)) { for (unsigned int i=0; i<lua_rawlen(L,-1); i++) { lua_pushinteger(L, i+1); lua_gettable(L, -2); if (lua_istable(L, -1) && lua_rawlen(L,-1) == 4) { lua_pushinteger(L, 1); lua_gettable(L, -2); s.gunMount[i].pos = LuaVector::CheckFromLuaF(L, -1); lua_pop(L, 1); lua_pushinteger(L, 2); lua_gettable(L, -2); s.gunMount[i].dir = LuaVector::CheckFromLuaF(L, -1); lua_pop(L, 1); lua_pushinteger(L, 3); lua_gettable(L, -2); s.gunMount[i].sep = lua_tonumber(L,-1); lua_pop(L, 1); lua_pushinteger(L, 4); lua_gettable(L, -2); s.gunMount[i].orient = static_cast<ShipType::DualLaserOrientation>( LuaConstants::GetConstantFromArg(L, "DualLaserOrientation", -1)); lua_pop(L, 1); } lua_pop(L, 1); } } lua_pop(L, 1); LUA_DEBUG_END(L, 0); //sanity check if (s.name.empty()) return luaL_error(L, "Ship has no name"); if (s.lmrModelName.empty()) return luaL_error(L, "Missing model name in ship"); //this shouldn't necessarily be a fatal problem, could just warn+mark ship unusable //or replace with proxy geometry try { LmrLookupModelByName(s.lmrModelName.c_str()); } catch (LmrModelNotFoundException &) { return luaL_error(L, "Model %s is not defined", s.lmrModelName.c_str()); } const std::string& id = s_currentShipFile; typedef std::map<ShipType::Type, ShipType>::iterator iter; std::pair<iter, bool> result = ShipType::types.insert(std::make_pair(id, s)); if (result.second) list->push_back(s_currentShipFile); else return luaL_error(L, "Ship '%s' was already defined by a different file", id.c_str()); s_currentShipFile.clear(); return 0; }
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.seed(time(0)); InitJoysticks(); joystickEnabled = (config->Int("EnableJoystick")) ? true : false; mouseYInvert = (config->Int("InvertMouseY")) ? true : false; navTunnelDisplayed = (config->Int("DisplayNavTunnel")) ? true : false; // 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); LmrModelCompilerInit(Pi::renderer); 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]; ShipType::Init(); draw_progress(0.6f); GeoSphere::Init(); draw_progress(0.7f); CityOnPlanet::Init(); draw_progress(0.8f); SpaceStation::Init(); draw_progress(0.9f); 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,lmrname,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) { ShipType *shipdef = &(i->second); LmrModel *lmrModel = LmrLookupModelByName(shipdef->lmrModelName.c_str()); LmrObjParams lmrParams; memset(&lmrParams, 0, sizeof(LmrObjParams)); lmrParams.animationNamespace = "ShipAnimation"; EquipSet equip; equip.InitSlotSizes(shipdef->id); lmrParams.equipment = &equip; LmrCollMesh *collMesh = new LmrCollMesh(lmrModel, &lmrParams); Aabb aabb = collMesh->GetAabb(); double hullmass = shipdef->hullMass; double capacity = shipdef->capacity; double xsize = aabb.max.x-aabb.min.x; double ysize = aabb.max.y-aabb.min.y; double zsize = aabb.max.z-aabb.min.z; double fakevol = xsize*ysize*zsize; double rescale = pow(fakevol/(100 * (hullmass+capacity)), 0.3333333333); double brad = aabb.GetRadius(); 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->linThrust[ShipType::THRUSTER_FORWARD] / (shipdef->fuelTankMass * shipdef->thrusterFuelUse * 10 * 1e6); fprintf(pStatFile, "%s,%s,%.1f,%.1f,%.1f,%.3f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%f,%.1f\n", shipdef->name.c_str(), shipdef->lmrModelName.c_str(), hullmass, capacity, fakevol, rescale, xsize, ysize, zsize, acc1, acc2, acc3, acc4, acca, exvel); delete collMesh; } fclose(pStatFile); } #endif luaConsole = new LuaConsole(10); KeyBindings::toggleLuaConsole.onPress.connect(sigc::ptr_fun(&Pi::ToggleLuaConsole)); gameMenuView = new GameMenuView(); config->Save(); }
int main(int argc, char **argv) { if ((argc<=1) || (0==strcmp(argv[1],"--help"))) { printf("Usage:\nluamodelviewer <width> <height> <model name>\n"); } if (argc >= 3) { g_width = atoi(argv[1]); g_height = atoi(argv[2]); } else { g_width = 800; g_height = 600; } const SDL_VideoInfo *info = NULL; if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError()); exit(-1); } info = SDL_GetVideoInfo(); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); g_zbias = 2.0/(1<<16); Uint32 flags = SDL_OPENGL; if ((g_screen = SDL_SetVideoMode(g_width, g_height, info->vfmt->BitsPerPixel, flags)) == 0) { // fall back on 16-bit depth buffer... SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); fprintf(stderr, "Failed to set video mode. (%s). Re-trying with 16-bit depth buffer.\n", SDL_GetError()); if ((g_screen = SDL_SetVideoMode(g_width, g_height, info->vfmt->BitsPerPixel, flags)) == 0) { fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError()); } } glewInit(); glShadeModel(GL_SMOOTH); glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glGenTextures(1, &mytexture); glBindTexture(GL_TEXTURE_2D, mytexture); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glClearColor(0,0,0,0); glViewport(0, 0, g_width, g_height); GLFTInit(); Render::Init(g_width, g_height); Gui::Init(g_width, g_height, g_width, g_height); LmrModelCompilerInit(); g_viewer = new Viewer(); if (argc >= 4) { g_viewer->SetModel(LmrLookupModelByName(argv[3])); } else { g_viewer->PickModel(); } g_viewer->MainLoop(); return 0; }