GameModel::GameModel(): sim(NULL), ren(NULL), currentBrush(0), currentUser(0, ""), currentSave(NULL), currentFile(NULL), colourSelector(false), clipboard(NULL), stamp(NULL), placeSave(NULL), colour(255, 0, 0, 255), toolStrength(1.0f), activeColourPreset(-1), activeMenu(-1), edgeMode(0) { sim = new Simulation(); ren = new Renderer(ui::Engine::Ref().g, sim); activeTools = regularToolset; std::fill(decoToolset, decoToolset+4, (Tool*)NULL); std::fill(regularToolset, regularToolset+4, (Tool*)NULL); //Default render prefs std::vector<unsigned int> tempArray; tempArray.push_back(RENDER_FIRE); tempArray.push_back(RENDER_EFFE); tempArray.push_back(RENDER_BASC); ren->SetRenderMode(tempArray); tempArray.clear(); ren->SetDisplayMode(tempArray); ren->SetColourMode(0); //Load config into renderer try { ren->SetColourMode(Client::Ref().GetPrefUInteger("Renderer.ColourMode", 0)); vector<unsigned int> tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.DisplayModes"); if(tempArray.size()) { std::vector<unsigned int> displayModes(tempArray.begin(), tempArray.end()); ren->SetDisplayMode(displayModes); } tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.RenderModes"); if(tempArray.size()) { std::vector<unsigned int> renderModes(tempArray.begin(), tempArray.end()); ren->SetRenderMode(renderModes); } ren->gravityFieldEnabled = Client::Ref().GetPrefBool("Renderer.GravityField", false); ren->decorations_enable = Client::Ref().GetPrefBool("Renderer.Decorations", true); } catch(json::Exception & e) { } //Load config into simulation edgeMode = Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0); sim->SetEdgeMode(edgeMode); int ngrav_enable = Client::Ref().GetPrefInteger("Simulation.NewtonianGravity", 0); if (ngrav_enable) sim->grav->start_grav_async(); sim->aheat_enable = Client::Ref().GetPrefInteger("Simulation.AmbientHeat", 0); sim->pretty_powder = Client::Ref().GetPrefInteger("Simulation.PrettyPowder", 0); //Load last user if(Client::Ref().GetAuthUser().ID) { currentUser = Client::Ref().GetAuthUser(); } //Set stamp to first stamp in list vector<string> stamps = Client::Ref().GetStamps(0, 1); if(stamps.size()>0) { SaveFile * stampFile = Client::Ref().GetStamp(stamps[0]); if(stampFile && stampFile->GetGameSave()) stamp = stampFile->GetGameSave(); } BuildMenus(); //Set default brush palette brushList.push_back(new EllipseBrush(ui::Point(4, 4))); brushList.push_back(new Brush(ui::Point(4, 4))); brushList.push_back(new TriangleBrush(ui::Point(4, 4))); //Load more from brushes folder std::vector<string> brushFiles = Client::Ref().DirectorySearch(BRUSH_DIR, "", ".ptb"); for(int i = 0; i < brushFiles.size(); i++) { std::vector<unsigned char> brushData = Client::Ref().ReadFile(brushFiles[i]); if(!brushData.size()) { std::cout << "Brushes: Skipping " << brushFiles[i] << ". Could not open" << std::endl; continue; } int dimension = std::sqrt((float)brushData.size()); if(dimension * dimension != brushData.size()) { std::cout << "Brushes: Skipping " << brushFiles[i] << ". Invalid bitmap size" << std::endl; continue; } brushList.push_back(new BitmapBrush(brushData, ui::Point(dimension, dimension))); } //Set default decoration colour unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255); unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255); unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255); unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255); SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA)); colourPresets.push_back(ui::Colour(255, 255, 255)); colourPresets.push_back(ui::Colour(0, 255, 255)); colourPresets.push_back(ui::Colour(255, 0, 255)); colourPresets.push_back(ui::Colour(255, 255, 0)); colourPresets.push_back(ui::Colour(255, 0, 0)); colourPresets.push_back(ui::Colour(0, 255, 0)); colourPresets.push_back(ui::Colour(0, 0, 255)); colourPresets.push_back(ui::Colour(0, 0, 0)); }
GameModel::GameModel(): sim(NULL), ren(NULL), currentBrush(0), currentUser(0, ""), currentSave(NULL), colourSelector(false), clipboard(NULL), stamp(NULL), placeSave(NULL), colour(255, 0, 0, 255), toolStrength(1.0f) { sim = new Simulation(); ren = new Renderer(ui::Engine::Ref().g, sim); memset(activeTools, 0, sizeof(activeTools)); //Load config into renderer try { ren->SetColourMode(Client::Ref().GetPrefUInteger("Renderer.ColourMode", 0)); vector<unsigned int> tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.DisplayModes"); if(tempArray.size()) { std::vector<unsigned int> displayModes(tempArray.begin(), tempArray.end()); ren->SetDisplayMode(displayModes); } tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.RenderModes"); if(tempArray.size()) { std::vector<unsigned int> renderModes(tempArray.begin(), tempArray.end()); ren->SetRenderMode(renderModes); } } catch(json::Exception & e) { } //Load config into simulation sim->SetEdgeMode(Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0)); //Load last user if(Client::Ref().GetAuthUser().ID) { currentUser = Client::Ref().GetAuthUser(); } //Set stamp to first stamp in list vector<string> stamps = Client::Ref().GetStamps(0, 1); if(stamps.size()>0) { SaveFile * stampFile = Client::Ref().GetStamp(stamps[0]); if(stampFile && stampFile->GetGameSave()) stamp = stampFile->GetGameSave(); } BuildMenus(); BuildQuickOptionMenu(); //Set default decoration colour unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255); unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255); unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255); unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255); SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA)); }
GameModel::GameModel(): sim(NULL), ren(NULL), currentBrush(0), currentUser(0, ""), currentSave(NULL), currentFile(NULL), colourSelector(false), clipboard(NULL), stamp(NULL), placeSave(NULL), colour(255, 0, 0, 255), toolStrength(1.0f), activeColourPreset(-1), activeMenu(NULL), edgeMode(0) { sim = new Simulation(); ren = new Renderer(ui::Engine::Ref().g, sim); activeTools = regularToolset; std::fill(decoToolset, decoToolset+3, (Tool*)NULL); std::fill(regularToolset, regularToolset+3, (Tool*)NULL); //Default render prefs std::vector<unsigned int> tempArray; tempArray.push_back(RENDER_FIRE); tempArray.push_back(RENDER_EFFE); tempArray.push_back(RENDER_BASC); ren->SetRenderMode(tempArray); tempArray.clear(); ren->SetDisplayMode(tempArray); ren->SetColourMode(0); //Load config into renderer try { ren->SetColourMode(Client::Ref().GetPrefUInteger("Renderer.ColourMode", 0)); vector<unsigned int> tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.DisplayModes"); if(tempArray.size()) { std::vector<unsigned int> displayModes(tempArray.begin(), tempArray.end()); ren->SetDisplayMode(displayModes); } tempArray = Client::Ref().GetPrefUIntegerArray("Renderer.RenderModes"); if(tempArray.size()) { std::vector<unsigned int> renderModes(tempArray.begin(), tempArray.end()); ren->SetRenderMode(renderModes); } ren->gravityFieldEnabled = Client::Ref().GetPrefBool("Renderer.GravityField", false); ren->decorations_enable = Client::Ref().GetPrefBool("Renderer.Decorations", true); } catch(json::Exception & e) { } //Load config into simulation edgeMode = Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0); sim->SetEdgeMode(edgeMode); //Load last user if(Client::Ref().GetAuthUser().ID) { currentUser = Client::Ref().GetAuthUser(); } //Set stamp to first stamp in list vector<string> stamps = Client::Ref().GetStamps(0, 1); if(stamps.size()>0) { SaveFile * stampFile = Client::Ref().GetStamp(stamps[0]); if(stampFile && stampFile->GetGameSave()) stamp = stampFile->GetGameSave(); } BuildMenus(); //Set default decoration colour unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255); unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255); unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255); unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255); SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA)); colourPresets.push_back(ui::Colour(255, 255, 255)); colourPresets.push_back(ui::Colour(0, 255, 255)); colourPresets.push_back(ui::Colour(255, 0, 255)); colourPresets.push_back(ui::Colour(255, 255, 0)); colourPresets.push_back(ui::Colour(255, 0, 0)); colourPresets.push_back(ui::Colour(0, 255, 0)); colourPresets.push_back(ui::Colour(0, 0, 255)); }