~ubuntu-branches/ubuntu/wily/xmoto/wily-proposed

« back to all changes in this revision

Viewing changes to src/RendererInit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-09-14 21:01:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060914210120-bvr7yu9rafb3fivp
Tags: 0.2.1-1
* New upstream release.
* Removed manpages and desktop files from the Debian package as they are now
  provided upstream.
* Make the package binNMUable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
  /*===========================================================================
34
34
  Init at game start-up
35
35
  ===========================================================================*/
36
 
  void GameRenderer::init(void) {
37
 
    /* Load sprite definitions. Sprites are very renderer specific in the
38
 
       meaning that they serve only a visual purpose - hence they are handled
39
 
       here in the renderer.  */
40
 
    XMLDocument Sprites;
41
 
        
42
 
    Sprites.readFromFile("sprites.dat");
43
 
    TiXmlDocument *pSprites = Sprites.getLowLevelAccess();
44
 
    if(pSprites == NULL) {
45
 
      /* No sprite definitions! */
46
 
      Log("** Warning ** : failed to load sprite definitions from 'sprites.dat'");
47
 
    }
48
 
    else {
49
 
      TiXmlElement *pSpriteDataElem = pSprites->FirstChildElement("spritedata");
50
 
      if(pSpriteDataElem == NULL) {
51
 
        /* No valid spritedata-element */
52
 
        Log("** Warning ** : 'sprites.dat' does not contain valid sprite data");
53
 
      }
54
 
      else {
55
 
        /* For each sprite */
56
 
        for(TiXmlElement *pSpriteElem=pSpriteDataElem->FirstChildElement("sprite");
57
 
            pSpriteElem!=NULL;pSpriteElem=pSpriteElem->NextSiblingElement("sprite")) {
58
 
          /* Load definition */
59
 
          const char *pc;
60
 
          std::string Name;
61
 
          pc = pSpriteElem->Attribute("name");
62
 
          if(pc != NULL) Name = pc;
63
 
          else Name = "";
64
 
          
65
 
          Vector2f Size(1,1);
66
 
          Vector2f Center(0.5,0.5);
67
 
          
68
 
          TiXmlElement *pSizeElem = pSpriteElem->FirstChildElement("size");
69
 
          TiXmlElement *pCenterElem = pSpriteElem->FirstChildElement("center");
70
 
          
71
 
          pc=pSizeElem->Attribute("width");
72
 
          if(pc != NULL) Size.x = atof(pc);
73
 
 
74
 
          pc=pSizeElem->Attribute("height");
75
 
          if(pc != NULL) Size.y = atof(pc);
76
 
 
77
 
          pc=pCenterElem->Attribute("x");
78
 
          if(pc != NULL) Center.x = atof(pc);
79
 
          else Center.x = Size.x/2.0f;
80
 
 
81
 
          pc=pCenterElem->Attribute("y");
82
 
          if(pc != NULL) Center.y = atof(pc);
83
 
          else Center.y = Size.y/2.0f;
84
 
 
85
 
          /* Load sprite */
86
 
          std::string TryPath = std::string("./Textures/Sprites/") + Name + std::string(".png");
87
 
          Texture *pTexture = getParent()->TexMan.loadTexture(TryPath,false,true,true);
88
 
          if(pTexture == NULL) {
89
 
            /* Could not load it */
90
 
            Log("** Warning ** : Sprite '%s' failed to load",TryPath.c_str());
91
 
          }
92
 
          else {
93
 
            m_SpriteTypes[m_nNumSpriteTypes].Name = Name;
94
 
            m_SpriteTypes[m_nNumSpriteTypes].Center = Center;
95
 
            m_SpriteTypes[m_nNumSpriteTypes].Size = Size;
96
 
            m_SpriteTypes[m_nNumSpriteTypes].pTexture = pTexture;
97
 
            m_nNumSpriteTypes++;
98
 
          }
99
 
        }
100
 
      }
101
 
    }
102
 
    Log(" %d sprite%s loaded",m_nNumSpriteTypes,m_nNumSpriteTypes==1?"":"s");           
103
 
    
104
 
    /* Load animations in the same way */
105
 
    XMLDocument Anims;
106
 
    int nTotalFrames = 0;
107
 
    Anims.readFromFile("anims.dat");
108
 
    TiXmlDocument *pAnims = Anims.getLowLevelAccess();
109
 
    if(pAnims == NULL) {
110
 
      /* No animation definitions! */
111
 
      Log("** Warning ** : failed to load animations from 'anims.dat'");
112
 
    }
113
 
    else {
114
 
      TiXmlElement *pAnimationDataElem = pAnims->FirstChildElement("animationdata");
115
 
      if(pAnimationDataElem == NULL) {
116
 
        /* No valid animationdata-element */
117
 
        Log("** Warning ** : 'anims.dat' does not contain valid animation data");
118
 
      }
119
 
      else {
120
 
        /* For each animation */
121
 
        for(TiXmlElement *pAnimationElem=pAnimationDataElem->FirstChildElement("animation");
122
 
            pAnimationElem!=NULL;pAnimationElem=pAnimationElem->NextSiblingElement("animation")) {
123
 
          /* Load definition */
124
 
          const char *pc;
125
 
          std::string Name;
126
 
          pc = pAnimationElem->Attribute("name");
127
 
          if(pc != NULL) Name = pc;
128
 
          else Name = "";
129
 
          
130
 
          /* Current settings (can be changed prior to each frame) */
131
 
          Vector2f Size(1,1);
132
 
          Vector2f Center(0.5,0.5);
133
 
          float fDelay=0.1f;
134
 
 
135
 
          /* Allocate and register animation */
136
 
          Animation *pAnim = new Animation;
137
 
          m_Anims.push_back( pAnim );
138
 
          pAnim->Name = Name;
139
 
          pAnim->fFrameTime = 0.0f;
140
 
          pAnim->m_nCurFrame = 0;
141
 
          
142
 
          /* Go trough definition... */
143
 
          for(TiXmlElement *pi=pAnimationElem->FirstChildElement();pi!=NULL;pi=pi->NextSiblingElement()) {
144
 
            std::string Type = pi->Value();
145
 
                        
146
 
            if(Type == "size") {
147
 
              pc = pi->Attribute("width");
148
 
              if(pc != NULL) Size.x = atof(pc);
149
 
              pc = pi->Attribute("height");
150
 
              if(pc != NULL) Size.y = atof(pc);
151
 
            }
152
 
            else if(Type == "center") {
153
 
              pc = pi->Attribute("x");
154
 
              if(pc != NULL) Center.x = atof(pc);
155
 
              pc = pi->Attribute("y");
156
 
              if(pc != NULL) Center.y = atof(pc);
157
 
            }
158
 
            else if(Type == "delay") {
159
 
              pc = pi->Attribute("time");
160
 
              if(pc != NULL) fDelay = atof(pc);
161
 
            }
162
 
            else if(Type == "frame") {
163
 
              pc = pi->Attribute("file");
164
 
              if(pc != NULL) {
165
 
                std::string Path = std::string("./Textures/") + std::string(pc);
166
 
              
167
 
                Texture *pTex = getParent()->TexMan.loadTexture(Path.c_str());
168
 
                if(pTex != NULL) {              
169
 
                  AnimationFrame *pFrame = new AnimationFrame;
170
 
                  pAnim->m_Frames.push_back(pFrame);
171
 
                  pFrame->pTexture = pTex;
172
 
                  pFrame->Center = Center;
173
 
                  pFrame->Size = Size;
174
 
                  pFrame->fDelay = fDelay;
175
 
                  nTotalFrames++;
176
 
                }
177
 
              }
178
 
            }
179
 
            else 
180
 
              Log("** Warning ** : unknown element '%s' in animation '%s'",Type.c_str(),Name.c_str());
181
 
          }
182
 
        }
183
 
      }
184
 
    }
185
 
    Log(" %d animation%s (%d total frame%s) loaded",m_Anims.size(),m_Anims.size()==1?"":"s",
186
 
                                                    nTotalFrames,nTotalFrames==1?"":"s");    
187
 
        
188
 
    m_pArrowTexture = getParent()->TexMan.loadTexture("Textures/Misc/Arrow.png");
189
 
            
190
 
    /* Load misc. textures */
191
 
    m_pSkyTexture1 = getParent()->TexMan.loadTexture("Textures/Effects/Sky1.jpg");
192
 
    m_pSkyTexture2 = getParent()->TexMan.loadTexture("Textures/Effects/Sky2.jpg");
193
 
    m_pSkyTexture2Drift = getParent()->TexMan.loadTexture("Textures/Effects/Sky2Drift.jpg");        
194
 
    m_pEdgeGrass1 = getParent()->TexMan.loadTexture("Textures/Effects/EdgeGrass1.png");
195
 
    
196
 
    m_pSmoke1 = getParent()->TexMan.loadTexture("Textures/Effects/Smoke1.png");
197
 
    m_pSmoke2 = getParent()->TexMan.loadTexture("Textures/Effects/Smoke2.png");
198
 
    m_pFire1 = getParent()->TexMan.loadTexture("Textures/Effects/Fire1.png");
199
 
    m_pDirt1 = getParent()->TexMan.loadTexture("Textures/Effects/Debris1.png");
200
 
    
201
 
    /* Load bike textures */
202
 
    theme_normal.BikeBody = getParent()->TexMan.loadTexture("Textures/Bikes/Body1.png");
203
 
    theme_normal.BikeRear = getParent()->TexMan.loadTexture("Textures/Bikes/Rear1.png");
204
 
    theme_normal.BikeFront = getParent()->TexMan.loadTexture("Textures/Bikes/Front1.png");
205
 
    theme_normal.BikeWheel = getParent()->TexMan.loadTexture("Textures/Bikes/Wheel1.png");
206
 
    
207
 
    if(theme_normal.BikeBody == NULL || theme_normal.BikeRear == NULL || 
208
 
       theme_normal.BikeFront == NULL || theme_normal.BikeWheel == NULL)
209
 
      throw Exception("important bike texture missing");
210
 
      
211
 
    /* Load rider textures */
212
 
    theme_normal.RiderTorso = getParent()->TexMan.loadTexture("Textures/Riders/Torso1.png");
213
 
    theme_normal.RiderUpperLeg = getParent()->TexMan.loadTexture("Textures/Riders/UpperLeg1.png");
214
 
    theme_normal.RiderLowerLeg = getParent()->TexMan.loadTexture("Textures/Riders/LowerLeg1.png");
215
 
    theme_normal.RiderUpperArm = getParent()->TexMan.loadTexture("Textures/Riders/UpperArm1.png");
216
 
    theme_normal.RiderLowerArm = getParent()->TexMan.loadTexture("Textures/Riders/LowerArm1.png");
217
 
 
218
 
    if(theme_normal.RiderTorso == NULL || theme_normal.RiderUpperLeg == NULL || 
219
 
       theme_normal.RiderLowerArm == NULL || theme_normal.RiderLowerLeg == NULL || theme_normal.RiderUpperArm == NULL)
220
 
      throw Exception("important rider texture missing");
221
 
 
222
 
#if defined(ALLOW_GHOST)
223
 
    /* Load bike textures */
224
 
    theme_ghost.BikeBody = getParent()->TexMan.loadTexture("Textures/Bikes/Body_Ghost.png");
225
 
    theme_ghost.BikeRear = getParent()->TexMan.loadTexture("Textures/Bikes/Rear_Ghost.png");
226
 
    theme_ghost.BikeFront = getParent()->TexMan.loadTexture("Textures/Bikes/Front_Ghost.png");
227
 
    theme_ghost.BikeWheel = getParent()->TexMan.loadTexture("Textures/Bikes/Wheel_Ghost.png");
228
 
    
229
 
    if(theme_ghost.BikeBody == NULL || theme_ghost.BikeRear == NULL || 
230
 
       theme_ghost.BikeFront == NULL || theme_ghost.BikeWheel == NULL)
231
 
      throw Exception("important bike texture missing");
232
 
 
233
 
    /* Load ghost textures */
234
 
    theme_ghost.RiderTorso = getParent()->TexMan.loadTexture("Textures/Riders/Torso_Ghost.png");
235
 
    theme_ghost.RiderUpperLeg = getParent()->TexMan.loadTexture("Textures/Riders/UpperLeg_Ghost.png");
236
 
    theme_ghost.RiderLowerLeg = getParent()->TexMan.loadTexture("Textures/Riders/LowerLeg_Ghost.png");
237
 
    theme_ghost.RiderUpperArm = getParent()->TexMan.loadTexture("Textures/Riders/UpperArm_Ghost.png");
238
 
    theme_ghost.RiderLowerArm = getParent()->TexMan.loadTexture("Textures/Riders/LowerArm_Ghost.png");
239
 
 
240
 
    if(theme_ghost.RiderTorso == NULL || theme_ghost.RiderUpperLeg == NULL || 
241
 
       theme_ghost.RiderLowerArm == NULL || theme_ghost.RiderLowerLeg == NULL || theme_ghost.RiderUpperArm == NULL)
242
 
      throw Exception("important rider texture missing");
243
 
#endif 
244
 
    
245
 
    /* Obtain ref. to known animations */
246
 
    m_pStrawberryAnim = _GetAnimationByName("Strawberry");
247
 
    m_pFlowerAnim = _GetAnimationByName("Flower");
248
 
    m_pWreckerAnim = _GetAnimationByName("Wrecker");
249
 
    
250
 
    if(m_pStrawberryAnim == NULL || m_pFlowerAnim == NULL || m_pWreckerAnim == NULL)
251
 
      throw Exception("important animation missing");
252
 
      
 
36
  void GameRenderer::init(void) { 
 
37
          
253
38
    /* Init GUI */
254
39
    getGUI()->setApp(getParent());
255
40
    getGUI()->setPosition(0,0,getParent()->getDispWidth(),getParent()->getDispHeight());
318
103
    m_Overlay.init(getParent(),512,512);
319
104
  }
320
105
 
321
 
};
 
106
}
322
107