2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "openal_wrapper.h"
24 #include "Animation.h"
26 extern float screenwidth,screenheight;
27 extern float viewdistance;
29 extern XYZ lightlocation;
30 extern float lightambient[3],lightbrightness[3];
31 extern float fadestart;
32 extern float texscale;
35 extern Skeleton testskeleton;
37 extern Terrain terrain;
38 //extern Sprites sprites;
39 extern int kTextureSize;
40 extern float texdetail;
41 extern float realtexdetail;
43 extern Objects objects;
45 extern bool cellophane;
46 extern GLubyte bloodText[512*512*3];
47 extern GLubyte wolfbloodText[512*512*3];
48 extern bool ismotionblur;
49 extern bool trilinear;
51 extern bool musictoggle;
52 extern int environment;
53 extern bool ambientsound;
54 extern float multiplier;
55 extern int netdatanew;
57 extern bool stillloading;
58 extern TGAImageRec texture;
62 extern int oldmainmenu;
63 extern bool visibleloading;
64 extern int loadscreencolor;
65 extern float flashamount,flashr,flashg,flashb;
66 extern int flashdelay;
67 extern int whichjointstartarray[26];
68 extern int whichjointendarray[26];
69 extern int difficulty;
70 extern float tintr,tintg,tintb;
71 extern float slomospeed;
72 extern bool gamestarted;
74 extern int numdialogues;
75 extern int numdialogueboxes[20];
76 extern int dialoguetype[20];
77 extern int dialogueboxlocation[20][20];
78 extern float dialogueboxcolor[20][20][3];
79 extern int dialogueboxsound[20][20];
80 extern char dialoguetext[20][20][128];
81 extern char dialoguename[20][20][64];
82 extern XYZ dialoguecamera[20][20];
83 extern float dialoguecamerarotation[20][20];
84 extern float dialoguecamerarotation2[20][20];
85 extern int indialogue;
86 extern int whichdialogue;
87 extern float dialoguetime;
89 extern float accountcampaignhighscore[10];
90 extern float accountcampaignfasttime[10];
91 extern float accountcampaignscore[10];
92 extern float accountcampaigntime[10];
94 extern int accountcampaignchoicesmade[10];
95 extern int accountcampaignchoices[10][5000];
97 void LOG(const std::string &fmt, ...)
99 // !!! FIXME: write me.
103 Game::TextureList Game::textures;
112 accountactive->endGame();
116 Account::saveFile(":Data:Users", accountactive);
118 TexIter it = textures.begin();
119 for (; it != textures.end(); ++it)
121 if (glIsTexture(it->second))
122 glDeleteTextures(1, &it->second);
126 LOG("Shutting down sound system...");
128 OPENAL_StopSound(OPENAL_ALL);
130 // this is causing problems on Linux, but we'll force an _exit() a little
131 // later in the shutdown process. --ryan.
134 for (i=0; i < sounds_count; ++i)
136 OPENAL_Sample_Free(samp[i]);
149 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
155 LOG(std::string("Loading texture...") + fileName);
157 // Fix filename so that is os appropreate
158 char * fixedFN = ConvertFileName(fileName);
160 unsigned char fileNamep[256];
161 CopyCStringToPascal(fixedFN, fileNamep);
163 upload_image( fileNamep ,hasalpha);
165 // std::string fname(fileName);
166 // std::transform(fname.begin(), fname.end(), tolower);
167 // TexIter it = textures.find(fname);
171 //if(textures.end() == it)
174 if ( texture.bpp == 24 )
179 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
182 glGenTextures( 1, textureid );
183 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
185 glBindTexture( GL_TEXTURE_2D, *textureid);
186 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
187 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
188 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
189 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
191 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
195 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
203 LOG(std::string("Loading texture (S)...") + fileName);
206 unsigned char fileNamep[256];
207 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
209 upload_image( fileNamep ,0);
210 //LoadTGA( fileName );
212 // std::string fname(fileName);
213 // std::transform(fname.begin(), fname.end(), tolower);
214 // TexIter it = textures.find(fname);
218 //if(textures.end() == it)
220 bytesPerPixel=texture.bpp/8;
223 if ( texture.bpp == 24 )
228 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
230 if(!*textureid)glGenTextures( 1, textureid );
231 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
233 glBindTexture( GL_TEXTURE_2D, *textureid);
234 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
235 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
236 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
237 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
240 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
241 if((i+1)%4||type==GL_RGB){
242 array[tempnum]=texture.data[i];
247 *skinsize=texture.sizeX;
249 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
251 // textures.insert(std::make_pair(fname, *textureid));
255 // *textureid = it->second;
259 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
266 LOG(std::string("Loading (S)...") + fileName);
269 float temptexdetail=texdetail;
271 //upload_image( fileName );
272 //LoadTGA( fileName );
274 // Converting file to something os specific
275 char * fixedFN = ConvertFileName(fileName);
278 unsigned char fileNamep[256];
279 CopyCStringToPascal(fixedFN, fileNamep);
281 upload_image( fileNamep ,0);
282 texdetail=temptexdetail;
286 bytesPerPixel=texture.bpp/8;
289 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
290 if((i+1)%4||bytesPerPixel==3){
291 array[tempnum]=texture.data[i];
298 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
305 //upload_image( fileName );
306 //LoadTGA( fileName );
308 unsigned char fileNamep[256];
309 CopyCStringToPascal(fileName,fileNamep);
312 opened=upload_image( fileNamep ,1);
325 bytesPerPixel=texture.bpp/8;
329 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
330 if(bytesPerPixel==3)alphanum=255;
331 else if((i+1)%4==0)alphanum=texture.data[i];
333 if((i+1)%4||bytesPerPixel==3){
334 if((i%4)==0)texture.data[i]*=tintr;
335 if((i%4)==1)texture.data[i]*=tintg;
336 if((i%4)==2)texture.data[i]*=tintb;
337 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
347 //***************> ResizeGLScene() <******/
348 GLvoid Game::ReSizeGLScene(float fov, float pnear)
355 glViewport(0,0,screenwidth,screenheight);
357 glMatrixMode(GL_PROJECTION);
360 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
362 glMatrixMode(GL_MODELVIEW);
366 void Game::LoadingScreen()
368 static float loadprogress,minprogress,maxprogress;
369 static AbsoluteTime time = {0,0};
370 static AbsoluteTime frametime = {0,0};
371 AbsoluteTime currTime = UpTime ();
372 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
374 if (0 > deltaTime) // if negative microseconds
375 deltaTime /= -1000000.0;
376 else // else milliseconds
379 multiplier=deltaTime;
380 if(multiplier<.001)multiplier=.001;
381 if(multiplier>10)multiplier=10;
383 frametime = currTime; // reset for next time interval
388 glClearColor(0,0,0,1);
389 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
392 loadtime+=multiplier*4;
394 loadprogress=loadtime;
395 if(loadprogress>100)loadprogress=100;
397 //loadprogress=abs(Random()%100);
401 glEnable(GL_TEXTURE_2D);
402 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
403 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
404 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
405 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
406 glDisable(GL_CULL_FACE);
407 glDisable(GL_LIGHTING);
409 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
410 glPushMatrix(); // Store The Projection Matrix
411 glLoadIdentity(); // Reset The Projection Matrix
412 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
413 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
414 glPushMatrix(); // Store The Modelview Matrix
415 glLoadIdentity(); // Reset The Modelview Matrix
416 glTranslatef(screenwidth/2,screenheight/2,0);
417 glScalef((float)screenwidth/2,(float)screenheight/2,1);
418 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
420 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
421 //glColor4f(1,1,1,1);
422 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
423 if(loadscreencolor==1)glColor4f(1,0,0,1);
424 if(loadscreencolor==2)glColor4f(0,1,0,1);
425 if(loadscreencolor==3)glColor4f(0,0,1,1);
426 if(loadscreencolor==4)glColor4f(1,1,0,1);
427 if(loadscreencolor==5)glColor4f(1,0,1,1);
430 //glScalef(.25,.25,.25);
432 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
433 glVertex3f(-1, -1, 0.0f);
434 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
435 glVertex3f(1, -1, 0.0f);
436 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
437 glVertex3f(1, 1, 0.0f);
438 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
439 glVertex3f(-1, 1, 0.0f);
444 //glScalef(.25,.25,.25);
446 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
447 glVertex3f(-1, -1, 0.0f);
448 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
449 glVertex3f(1, -1, 0.0f);
450 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
451 glVertex3f(1, 1, 0.0f);
452 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
453 glVertex3f(-1, 1, 0.0f);
456 glDisable(GL_TEXTURE_2D);
457 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
458 glPopMatrix(); // Restore The Old Projection Matrix
459 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
460 glPopMatrix(); // Restore The Old Projection Matrix
464 glEnable(GL_TEXTURE_2D);
465 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
466 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
467 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
468 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
469 glDisable(GL_CULL_FACE);
470 glDisable(GL_LIGHTING);
472 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
473 glPushMatrix(); // Store The Projection Matrix
474 glLoadIdentity(); // Reset The Projection Matrix
475 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
476 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
477 glPushMatrix(); // Store The Modelview Matrix
478 glLoadIdentity(); // Reset The Modelview Matrix
479 glTranslatef(screenwidth/2,screenheight/2,0);
480 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
481 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
483 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
484 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
485 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
486 if(loadscreencolor==1)glColor4f(1,0,0,1);
487 if(loadscreencolor==2)glColor4f(0,1,0,1);
488 if(loadscreencolor==3)glColor4f(0,0,1,1);
489 if(loadscreencolor==4)glColor4f(1,1,0,1);
490 if(loadscreencolor==5)glColor4f(1,0,1,1);
493 //glScalef(.25,.25,.25);
495 glTexCoord2f(0+.5,0+.5);
496 glVertex3f(-1, -1, 0.0f);
497 glTexCoord2f(1+.5,0+.5);
498 glVertex3f(1, -1, 0.0f);
499 glTexCoord2f(1+.5,1+.5);
500 glVertex3f(1, 1, 0.0f);
501 glTexCoord2f(0+.5,1+.5);
502 glVertex3f(-1, 1, 0.0f);
505 glDisable(GL_TEXTURE_2D);
506 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
507 glPopMatrix(); // Restore The Old Projection Matrix
508 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
509 glPopMatrix(); // Restore The Old Projection Matrix
513 glEnable(GL_TEXTURE_2D);
514 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
515 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
516 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
517 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
518 glDisable(GL_CULL_FACE);
519 glDisable(GL_LIGHTING);
521 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
522 glPushMatrix(); // Store The Projection Matrix
523 glLoadIdentity(); // Reset The Projection Matrix
524 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
525 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
526 glPushMatrix(); // Store The Modelview Matrix
527 glLoadIdentity(); // Reset The Modelview Matrix
528 glTranslatef(screenwidth/2,screenheight/2,0);
529 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
530 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
532 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
534 //glScalef(.25,.25,.25);
536 glTexCoord2f(0+.2,0+.8);
537 glVertex3f(-1, -1, 0.0f);
538 glTexCoord2f(1+.2,0+.8);
539 glVertex3f(1, -1, 0.0f);
540 glTexCoord2f(1+.2,1+.8);
541 glVertex3f(1, 1, 0.0f);
542 glTexCoord2f(0+.2,1+.8);
543 glVertex3f(-1, 1, 0.0f);
546 glDisable(GL_TEXTURE_2D);
547 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
548 glPopMatrix(); // Restore The Old Projection Matrix
549 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
550 glPopMatrix(); // Restore The Old Projection Matrix
556 glEnable(GL_TEXTURE_2D);
557 static char string[256]="";
558 sprintf (string, "LOADING... %d%",(int)loadprogress);
560 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
561 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
562 text.glPrint(280,125,string,1,1,640,480);
566 if(flashamount>1)flashamount=1;
567 if(flashdelay<=0)flashamount-=multiplier;
569 if(flashamount<0)flashamount=0;
570 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
571 glDisable(GL_CULL_FACE);
572 glDisable(GL_LIGHTING);
573 glDisable(GL_TEXTURE_2D);
575 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
576 glPushMatrix(); // Store The Projection Matrix
577 glLoadIdentity(); // Reset The Projection Matrix
578 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
579 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
580 glPushMatrix(); // Store The Modelview Matrix
581 glLoadIdentity(); // Reset The Modelview Matrix
582 glScalef(screenwidth,screenheight,1);
583 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
585 glColor4f(flashr,flashg,flashb,flashamount);
587 glVertex3f(0, 0, 0.0f);
588 glVertex3f(256, 0, 0.0f);
589 glVertex3f(256, 256, 0.0f);
590 glVertex3f(0, 256, 0.0f);
592 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
593 glPopMatrix(); // Restore The Old Projection Matrix
594 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
595 glPopMatrix(); // Restore The Old Projection Matrix
596 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
597 glEnable(GL_CULL_FACE);
607 void Game::FadeLoadingScreen(float howmuch)
609 static float loadprogress,minprogress,maxprogress;
614 glClearColor(0,0,0,1);
615 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
617 loadprogress=howmuch;
619 //loadprogress=abs(Random()%100);
623 //glEnable(GL_TEXTURE_2D);
624 glDisable(GL_TEXTURE_2D);
625 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
626 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
627 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
628 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
629 glDisable(GL_CULL_FACE);
630 glDisable(GL_LIGHTING);
632 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
633 glPushMatrix(); // Store The Projection Matrix
634 glLoadIdentity(); // Reset The Projection Matrix
635 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
636 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
637 glPushMatrix(); // Store The Modelview Matrix
638 glLoadIdentity(); // Reset The Modelview Matrix
639 glTranslatef(screenwidth/2,screenheight/2,0);
640 glScalef((float)screenwidth/2,(float)screenheight/2,1);
641 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
643 glColor4f(loadprogress/100,0,0,1);
644 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
645 if(loadscreencolor==1)glColor4f(1,0,0,1);
646 if(loadscreencolor==2)glColor4f(0,1,0,1);
647 if(loadscreencolor==3)glColor4f(0,0,1,1);
648 if(loadscreencolor==4)glColor4f(1,1,0,1);
649 if(loadscreencolor==5)glColor4f(1,0,1,1);
652 //glScalef(.25,.25,.25);
655 glVertex3f(-1, -1, 0.0f);
657 glVertex3f(1, -1, 0.0f);
659 glVertex3f(1, 1, 0.0f);
661 glVertex3f(-1, 1, 0.0f);
664 glDisable(GL_TEXTURE_2D);
665 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
666 glPopMatrix(); // Restore The Old Projection Matrix
667 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
668 glPopMatrix(); // Restore The Old Projection Matrix
673 glEnable(GL_TEXTURE_2D);
674 static char string[256]="";
675 sprintf (string, "LOADING... %d%",(int)loadprogress);
677 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
678 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
679 text.glPrint(280,125,string,1,1,640,480);
686 void Game::InitGame()
689 ProcessSerialNumber PSN;
690 ProcessInfoRec pinfo;
693 /* set up process serial number */
694 PSN.highLongOfPSN = 0;
695 PSN.lowLongOfPSN = kCurrentProcess;
696 /* set up info block */
697 pinfo.processInfoLength = sizeof(pinfo);
698 pinfo.processName = NULL;
699 pinfo.processAppSpec = &pspec;
700 /* grab the vrefnum and directory */
701 err = GetProcessInformation(&PSN, &pinfo);
703 vRefNum = pspec.vRefNum;
714 numchallengelevels=14;
716 accountactive=Account::loadFile(":Data:Users");
722 whichjointstartarray[0]=righthip;
723 whichjointendarray[0]=rightfoot;
725 whichjointstartarray[1]=righthip;
726 whichjointendarray[1]=rightankle;
728 whichjointstartarray[2]=righthip;
729 whichjointendarray[2]=rightknee;
731 whichjointstartarray[3]=rightknee;
732 whichjointendarray[3]=rightankle;
734 whichjointstartarray[4]=rightankle;
735 whichjointendarray[4]=rightfoot;
737 whichjointstartarray[5]=lefthip;
738 whichjointendarray[5]=leftfoot;
740 whichjointstartarray[6]=lefthip;
741 whichjointendarray[6]=leftankle;
743 whichjointstartarray[7]=lefthip;
744 whichjointendarray[7]=leftknee;
746 whichjointstartarray[8]=leftknee;
747 whichjointendarray[8]=leftankle;
749 whichjointstartarray[9]=leftankle;
750 whichjointendarray[9]=leftfoot;
752 whichjointstartarray[10]=abdomen;
753 whichjointendarray[10]=rightshoulder;
755 whichjointstartarray[11]=abdomen;
756 whichjointendarray[11]=rightelbow;
758 whichjointstartarray[12]=abdomen;
759 whichjointendarray[12]=rightwrist;
761 whichjointstartarray[13]=abdomen;
762 whichjointendarray[13]=righthand;
764 whichjointstartarray[14]=rightshoulder;
765 whichjointendarray[14]=rightelbow;
767 whichjointstartarray[15]=rightelbow;
768 whichjointendarray[15]=rightwrist;
770 whichjointstartarray[16]=rightwrist;
771 whichjointendarray[16]=righthand;
773 whichjointstartarray[17]=abdomen;
774 whichjointendarray[17]=leftshoulder;
776 whichjointstartarray[18]=abdomen;
777 whichjointendarray[18]=leftelbow;
779 whichjointstartarray[19]=abdomen;
780 whichjointendarray[19]=leftwrist;
782 whichjointstartarray[20]=abdomen;
783 whichjointendarray[20]=lefthand;
785 whichjointstartarray[21]=leftshoulder;
786 whichjointendarray[21]=leftelbow;
788 whichjointstartarray[22]=leftelbow;
789 whichjointendarray[22]=leftwrist;
791 whichjointstartarray[23]=leftwrist;
792 whichjointendarray[23]=lefthand;
794 whichjointstartarray[24]=abdomen;
795 whichjointendarray[24]=neck;
797 whichjointstartarray[25]=neck;
798 whichjointendarray[25]=head;
800 FadeLoadingScreen(0);
804 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
806 int temptexdetail=texdetail;
808 text.LoadFontTexture(":Data:Textures:Font.png");
810 texdetail=temptexdetail;
812 FadeLoadingScreen(10);
824 LOG("Initializing sound system...");
829 extern bool cmdline(const char *cmd);
830 unsigned char rc = 0;
831 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
832 if (cmdline("forceoss")) // ...but let user override that.
833 output = OPENAL_OUTPUT_OSS;
834 else if (cmdline("nosound"))
835 output = OPENAL_OUTPUT_NOSOUND;
837 OPENAL_SetOutput(output);
838 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
840 // if we tried ALSA and failed, fall back to OSS.
841 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
844 output = OPENAL_OUTPUT_OSS;
845 OPENAL_SetOutput(output);
846 rc = OPENAL_Init(44100, 32, 0);
853 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
854 OPENAL_SetOutput(output);
855 rc = OPENAL_Init(44100, 32, 0);
858 OPENAL_Init(44100, 32, 0);
861 OPENAL_SetSFXMasterVolume((int)(volume*255));
865 emit_stream_np(stream_music3);
867 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
869 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
870 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
871 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
873 temptexdetail=texdetail;
874 if(texdetail>2)texdetail=2;
875 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
876 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
877 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
878 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
879 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
880 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
881 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
882 texdetail=temptexdetail;
887 FadeLoadingScreen(95);
898 newscreenwidth=screenwidth;
899 newscreenheight=screenheight;
903 void Game::LoadStuff()
905 static float temptexdetail;
906 static float viewdistdetail;
907 static int i,j,texsize;
918 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
920 for(i=0;i<maxplayers;i++)
922 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
924 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
926 player[i].skeleton.drawmodel.textureptr=0;;
929 //temptexdetail=texdetail;
932 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
933 //texdetail=temptexdetail;
935 temptexdetail=texdetail;
937 text.LoadFontTexture(":Data:Textures:Font.png");
939 texdetail=temptexdetail;
944 viewdistance=50*megascale*viewdistdetail;
960 realtexdetail=texdetail;
963 if(texdetail<1)texdetail=1;
964 realtexdetail=texdetail*4;
970 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
972 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
974 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
978 LOG("Loading weapon data...");
980 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
981 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
982 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
983 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
984 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
985 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
986 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
988 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
989 weapons.throwingknifemodel.Scale(.001,.001,.001);
990 //weapons.throwingknifemodel.Rotate(0,0,-90);
991 weapons.throwingknifemodel.Rotate(90,0,0);
992 weapons.throwingknifemodel.Rotate(0,90,0);
993 weapons.throwingknifemodel.flat=0;
994 weapons.throwingknifemodel.CalculateNormals(1);
995 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
997 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
998 weapons.swordmodel.Scale(.001,.001,.001);
999 //weapons.swordmodel.Rotate(0,0,-90);
1000 weapons.swordmodel.Rotate(90,0,0);
1001 weapons.swordmodel.Rotate(0,90,0);
1002 weapons.swordmodel.Rotate(0,0,90);
1003 weapons.swordmodel.flat=1;
1004 weapons.swordmodel.CalculateNormals(1);
1005 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1007 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1008 weapons.staffmodel.Scale(.005,.005,.005);
1009 //weapons.staffmodel.Rotate(0,0,-90);
1010 weapons.staffmodel.Rotate(90,0,0);
1011 weapons.staffmodel.Rotate(0,90,0);
1012 weapons.staffmodel.Rotate(0,0,90);
1013 weapons.staffmodel.flat=1;
1014 weapons.staffmodel.CalculateNormals(1);
1015 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1017 //temptexdetail=texdetail;
1018 //if(texdetail>4)texdetail=4;
1019 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1021 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1023 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1025 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1028 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1030 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1032 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1034 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1036 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1038 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1040 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1042 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1043 //texdetail=temptexdetail;
1044 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1048 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1050 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1053 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1056 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1057 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1058 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1059 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1060 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1061 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1062 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1063 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1064 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1065 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1066 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1070 ReSizeGLScene(90,.01);
1077 if(detail)kTextureSize=1024;
1078 if(detail==1)kTextureSize=512;
1079 if(detail==0)kTextureSize=256;
1082 //drawmode=motionblurmode;
1084 //Set up distant light
1088 light.ambient[0]=.2;
1089 light.ambient[1]=.2;
1090 light.ambient[2]=.24;
1093 light.location.z=-.2;
1094 Normalise(&light.location);
1104 texscale=.2/megascale/viewdistdetail;
1105 terrain.scale=3*megascale*viewdistdetail;
1107 viewer.x=terrain.size/2*terrain.scale;
1108 viewer.z=terrain.size/2*terrain.scale;
1110 hawk.load((char *)":Data:Models:hawk.solid",1);
1111 hawk.Scale(.03,.03,.03);
1112 hawk.Rotate(90,1,1);
1113 hawk.CalculateNormals(0);
1114 hawk.ScaleNormals(-1,-1,-1);
1115 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1116 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1117 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1120 eye.load((char *)":Data:Models:eye.solid",1);
1121 eye.Scale(.03,.03,.03);
1122 eye.CalculateNormals(0);
1124 cornea.load((char *)":Data:Models:cornea.solid",1);
1125 cornea.Scale(.03,.03,.03);
1126 cornea.CalculateNormals(0);
1128 iris.load((char *)":Data:Models:iris.solid",1);
1129 iris.Scale(.03,.03,.03);
1130 iris.CalculateNormals(0);
1132 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1133 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1141 //if(targetlevel!=7)
1142 Loadlevel(targetlevel);
1145 rabbitcoords=player[0].coords;
1146 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1148 loadAllAnimations();
1149 //Fix knife stab, too lazy to do it manually
1153 for(i=0;i<player[0].skeleton.num_joints;i++){
1154 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1155 animation[knifesneakattackanim].position[i][j]+=moveamount;
1162 for(i=0;i<player[0].skeleton.num_joints;i++){
1163 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1164 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1171 for(i=0;i<player[0].skeleton.num_joints;i++){
1172 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1173 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1174 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1175 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1177 animation[dead1anim].speed[0]=0.001;
1178 animation[dead2anim].speed[0]=0.001;
1179 animation[dead3anim].speed[0]=0.001;
1180 animation[dead4anim].speed[0]=0.001;
1182 animation[dead1anim].speed[1]=0.001;
1183 animation[dead2anim].speed[1]=0.001;
1184 animation[dead3anim].speed[1]=0.001;
1185 animation[dead4anim].speed[1]=0.001;
1187 for(i=0;i<player[0].skeleton.num_joints;i++){
1188 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1189 animation[swordsneakattackanim].position[i][j]+=moveamount;
1194 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1195 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1201 for(i=0;i<player[0].skeleton.num_joints;i++){
1202 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1203 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1207 for(i=0;i<player[0].skeleton.num_joints;i++){
1208 for(j=0;j<animation[sleepanim].numframes;j++){
1209 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1215 temptexdetail=texdetail;
1217 texdetail=temptexdetail;
1224 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1226 glGenTextures( 1, &screentexture );
1227 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1230 glEnable(GL_TEXTURE_2D);
1231 glBindTexture( GL_TEXTURE_2D, screentexture);
1232 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1233 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1235 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1239 emit_sound_at(fireendsound);