Theme.cpp

Go to the documentation of this file.
00001 
00005 /* Copyright © 2009, 2010 James Legg.
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 */
00011 #include "Theme.h"
00012 #include <iostream>
00013 #include "stream_loader.h"
00014 #include "FormErrors.h"
00015 
00016 #include <Debug.h>
00017 
00018 namespace Track
00019 {
00020 
00021 Theme::Theme(std::istream & source)
00022     :skybox(source)
00023     
00024 {
00025     fill_vector_from_stream<Segment>(segments, source);
00026     
00027     source >> m_use_sky_particles;
00028     
00029     find_default_segment();
00030     
00031     DEBUG_MESSAGE("Finished loading theme.");
00032 }
00033 
00034 Theme::~Theme()
00035 {
00036     DEBUG_MESSAGE("Theme destroyed.");
00037 }
00038 
00039 const Skybox & Theme::get_skybox() const
00040 {
00041     return skybox;
00042 }
00043 
00044 std::size_t Theme::get_number_of_segments() const
00045 {
00046     return segments.size();
00047 }
00048 
00049 const Segment & Theme::get_segment(std::size_t index) const
00050 {
00051     assert(index < segments.size());
00052     return *(segments[index]);
00053 }
00054 
00055 const std::string & Theme::get_name() const
00056 {
00057     return name;
00058 }
00059 
00060 std::size_t Theme::get_segment_index(std::string name) const
00061 {
00062     for (std::size_t index = 0;
00063          index < segments.size();
00064          index++)
00065     {
00066         if (segments[index]->get_name() == name)
00067         {
00068             // found it.
00069             return index;
00070         }
00071     }
00072     // Doesn't exist. The name probably came from a different version of this theme.
00073     assert(false);
00074     throw ThemeChangedError();
00075 }
00076 
00077 std::size_t Theme::get_default_segment_index() const
00078 {
00079     return m_default_segment_index;
00080 }
00081 
00082 bool Theme::get_use_sky_particles() const
00083 {
00084     return m_use_sky_particles;
00085 }
00086 
00087 void Theme::find_default_segment()
00088 {
00089     // find a good default segment.
00090     std::size_t edges_allowed = -1;
00091     std::size_t called_default = -1;
00092     std::size_t called_straight = -1;
00093     std::size_t count = segments.size();
00094     for (std::size_t i = 0; i < count; i++)
00095     {
00096         const Track::Segment & seg = *(segments[i]);
00097         if (seg.edges_allowed())
00098         {
00099             edges_allowed = i;
00100         }
00101         if (seg.get_name() == "default" || seg.get_name() == "Default")
00102         {
00103             called_default = i;
00104         }
00105         if (seg.get_name() == "straight" || seg.get_name() == "Straight")
00106         {
00107             called_straight = i;
00108         }
00109     }
00110     if (called_default != std::size_t(-1))
00111     {
00112         m_default_segment_index = called_default;
00113     }
00114     else if (called_straight != std::size_t(-1))
00115     {
00116         m_default_segment_index = called_straight;
00117     }
00118     else if (edges_allowed != std::size_t(-1))
00119     {
00120         m_default_segment_index = edges_allowed;
00121     } else {
00122         // theme shold probably not be allowed, nothing works for edges!
00123         m_default_segment_index = 0;
00124     }
00125 }
00126 
00127 }

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:12 2010 by Doxygen version 1.4.7 for Racer version svn335.