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 int channels[100];
38 extern Terrain terrain;
39 //extern Sprites sprites;
40 extern int kTextureSize;
41 extern float texdetail;
42 extern float realtexdetail;
43 extern float terraindetail;
45 extern Objects objects;
47 extern bool cellophane;
48 extern GLubyte bloodText[512*512*3];
49 extern GLubyte wolfbloodText[512*512*3];
50 extern bool ismotionblur;
51 extern bool trilinear;
53 extern bool musictoggle;
54 extern Weapons weapons;
55 extern Person player[maxplayers];
56 extern int numplayers;
57 extern int environment;
58 extern bool ambientsound;
59 extern float multiplier;
60 extern int netdatanew;
62 extern bool stillloading;
63 extern TGAImageRec texture;
67 extern int oldmainmenu;
68 extern bool visibleloading;
69 extern int loadscreencolor;
70 extern float flashamount,flashr,flashg,flashb;
71 extern int flashdelay;
72 extern int whichjointstartarray[26];
73 extern int whichjointendarray[26];
74 extern int difficulty;
75 extern float tintr,tintg,tintb;
76 extern float slomospeed;
77 extern char mapname[256];
78 extern bool gamestarted;
80 extern int numdialogues;
81 extern int numdialogueboxes[20];
82 extern int dialoguetype[20];
83 extern int dialogueboxlocation[20][20];
84 extern float dialogueboxcolor[20][20][3];
85 extern int dialogueboxsound[20][20];
86 extern char dialoguetext[20][20][128];
87 extern char dialoguename[20][20][64];
88 extern XYZ dialoguecamera[20][20];
89 extern float dialoguecamerarotation[20][20];
90 extern float dialoguecamerarotation2[20][20];
91 extern int indialogue;
92 extern int whichdialogue;
93 extern float dialoguetime;
95 extern float accountcampaignhighscore[10];
96 extern float accountcampaignfasttime[10];
97 extern float accountcampaignscore[10];
98 extern float accountcampaigntime[10];
100 extern int accountcampaignchoicesmade[10];
101 extern int accountcampaignchoices[10][5000];
103 extern OPENAL_STREAM * strm[20];
105 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
106 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
108 void LOG(const std::string &fmt, ...)
110 // !!! FIXME: write me.
114 Game::TextureList Game::textures;
123 accountactive->endGame();
127 Account::saveFile(":Data:Users", accountactive);
129 TexIter it = textures.begin();
130 for (; it != textures.end(); ++it)
132 if (glIsTexture(it->second))
133 glDeleteTextures(1, &it->second);
137 LOG("Shutting down sound system...");
139 OPENAL_StopSound(OPENAL_ALL);
141 // this is causing problems on Linux, but we'll force an _exit() a little
142 // later in the shutdown process. --ryan.
144 #define streamcount 20
145 #define samplecount 100
147 for (i=0; i < samplecount; ++i)
149 OPENAL_Sample_Free(samp[i]);
152 for (i=0; i < streamcount; ++i)
154 OPENAL_Stream_Close(strm[i]);
167 void Game::LoadSounds()
171 LOG(std::string("Loading sounds..."));
173 OPENAL_SetSFXMasterVolume((int)(volume*255));
175 if(visibleloading){LoadingScreen(); loadscreencolor=5;}
179 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
185 LOG(std::string("Loading texture...") + fileName);
187 // Fix filename so that is os appropreate
188 char * fixedFN = ConvertFileName(fileName);
190 unsigned char fileNamep[256];
191 CopyCStringToPascal(fixedFN, fileNamep);
193 upload_image( fileNamep ,hasalpha);
195 // std::string fname(fileName);
196 // std::transform(fname.begin(), fname.end(), tolower);
197 // TexIter it = textures.find(fname);
201 //if(textures.end() == it)
204 if ( texture.bpp == 24 )
209 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
212 glGenTextures( 1, textureid );
213 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
215 glBindTexture( GL_TEXTURE_2D, *textureid);
216 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
217 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
218 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
219 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
221 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
225 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
233 LOG(std::string("Loading texture (S)...") + fileName);
236 unsigned char fileNamep[256];
237 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
239 upload_image( fileNamep ,0);
240 //LoadTGA( fileName );
242 // std::string fname(fileName);
243 // std::transform(fname.begin(), fname.end(), tolower);
244 // TexIter it = textures.find(fname);
248 //if(textures.end() == it)
250 bytesPerPixel=texture.bpp/8;
253 if ( texture.bpp == 24 )
258 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
260 if(!*textureid)glGenTextures( 1, textureid );
261 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
263 glBindTexture( GL_TEXTURE_2D, *textureid);
264 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
265 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
266 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
267 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
270 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
271 if((i+1)%4||type==GL_RGB){
272 array[tempnum]=texture.data[i];
277 *skinsize=texture.sizeX;
279 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
281 // textures.insert(std::make_pair(fname, *textureid));
285 // *textureid = it->second;
289 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
296 LOG(std::string("Loading (S)...") + fileName);
299 float temptexdetail=texdetail;
301 //upload_image( fileName );
302 //LoadTGA( fileName );
304 // Converting file to something os specific
305 char * fixedFN = ConvertFileName(fileName);
308 unsigned char fileNamep[256];
309 CopyCStringToPascal(fixedFN, fileNamep);
311 upload_image( fileNamep ,0);
312 texdetail=temptexdetail;
316 bytesPerPixel=texture.bpp/8;
319 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
320 if((i+1)%4||bytesPerPixel==3){
321 array[tempnum]=texture.data[i];
328 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
335 //upload_image( fileName );
336 //LoadTGA( fileName );
338 unsigned char fileNamep[256];
339 CopyCStringToPascal(fileName,fileNamep);
342 opened=upload_image( fileNamep ,1);
355 bytesPerPixel=texture.bpp/8;
359 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
360 if(bytesPerPixel==3)alphanum=255;
361 else if((i+1)%4==0)alphanum=texture.data[i];
363 if((i+1)%4||bytesPerPixel==3){
364 if((i%4)==0)texture.data[i]*=tintr;
365 if((i%4)==1)texture.data[i]*=tintg;
366 if((i%4)==2)texture.data[i]*=tintb;
367 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
377 //***************> ResizeGLScene() <******/
378 GLvoid Game::ReSizeGLScene(float fov, float pnear)
385 glViewport(0,0,screenwidth,screenheight);
387 glMatrixMode(GL_PROJECTION);
390 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
392 glMatrixMode(GL_MODELVIEW);
396 void Game::LoadingScreen()
398 static float loadprogress,minprogress,maxprogress;
399 static AbsoluteTime time = {0,0};
400 static AbsoluteTime frametime = {0,0};
401 AbsoluteTime currTime = UpTime ();
402 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
404 if (0 > deltaTime) // if negative microseconds
405 deltaTime /= -1000000.0;
406 else // else milliseconds
409 multiplier=deltaTime;
410 if(multiplier<.001)multiplier=.001;
411 if(multiplier>10)multiplier=10;
413 frametime = currTime; // reset for next time interval
418 glClearColor(0,0,0,1);
419 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
422 loadtime+=multiplier*4;
424 loadprogress=loadtime;
425 if(loadprogress>100)loadprogress=100;
427 //loadprogress=abs(Random()%100);
431 glEnable(GL_TEXTURE_2D);
432 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
433 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
434 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
435 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
436 glDisable(GL_CULL_FACE);
437 glDisable(GL_LIGHTING);
439 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
440 glPushMatrix(); // Store The Projection Matrix
441 glLoadIdentity(); // Reset The Projection Matrix
442 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
443 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
444 glPushMatrix(); // Store The Modelview Matrix
445 glLoadIdentity(); // Reset The Modelview Matrix
446 glTranslatef(screenwidth/2,screenheight/2,0);
447 glScalef((float)screenwidth/2,(float)screenheight/2,1);
448 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
450 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
451 //glColor4f(1,1,1,1);
452 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
453 if(loadscreencolor==1)glColor4f(1,0,0,1);
454 if(loadscreencolor==2)glColor4f(0,1,0,1);
455 if(loadscreencolor==3)glColor4f(0,0,1,1);
456 if(loadscreencolor==4)glColor4f(1,1,0,1);
457 if(loadscreencolor==5)glColor4f(1,0,1,1);
460 //glScalef(.25,.25,.25);
462 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
463 glVertex3f(-1, -1, 0.0f);
464 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
465 glVertex3f(1, -1, 0.0f);
466 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
467 glVertex3f(1, 1, 0.0f);
468 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
469 glVertex3f(-1, 1, 0.0f);
474 //glScalef(.25,.25,.25);
476 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
477 glVertex3f(-1, -1, 0.0f);
478 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
479 glVertex3f(1, -1, 0.0f);
480 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
481 glVertex3f(1, 1, 0.0f);
482 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
483 glVertex3f(-1, 1, 0.0f);
486 glDisable(GL_TEXTURE_2D);
487 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
488 glPopMatrix(); // Restore The Old Projection Matrix
489 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
490 glPopMatrix(); // Restore The Old Projection Matrix
494 glEnable(GL_TEXTURE_2D);
495 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
496 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
497 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
498 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
499 glDisable(GL_CULL_FACE);
500 glDisable(GL_LIGHTING);
502 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
503 glPushMatrix(); // Store The Projection Matrix
504 glLoadIdentity(); // Reset The Projection Matrix
505 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
506 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
507 glPushMatrix(); // Store The Modelview Matrix
508 glLoadIdentity(); // Reset The Modelview Matrix
509 glTranslatef(screenwidth/2,screenheight/2,0);
510 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
511 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
513 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
514 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
515 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
516 if(loadscreencolor==1)glColor4f(1,0,0,1);
517 if(loadscreencolor==2)glColor4f(0,1,0,1);
518 if(loadscreencolor==3)glColor4f(0,0,1,1);
519 if(loadscreencolor==4)glColor4f(1,1,0,1);
520 if(loadscreencolor==5)glColor4f(1,0,1,1);
523 //glScalef(.25,.25,.25);
525 glTexCoord2f(0+.5,0+.5);
526 glVertex3f(-1, -1, 0.0f);
527 glTexCoord2f(1+.5,0+.5);
528 glVertex3f(1, -1, 0.0f);
529 glTexCoord2f(1+.5,1+.5);
530 glVertex3f(1, 1, 0.0f);
531 glTexCoord2f(0+.5,1+.5);
532 glVertex3f(-1, 1, 0.0f);
535 glDisable(GL_TEXTURE_2D);
536 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
537 glPopMatrix(); // Restore The Old Projection Matrix
538 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
539 glPopMatrix(); // Restore The Old Projection Matrix
543 glEnable(GL_TEXTURE_2D);
544 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
545 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
546 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
547 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
548 glDisable(GL_CULL_FACE);
549 glDisable(GL_LIGHTING);
551 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
552 glPushMatrix(); // Store The Projection Matrix
553 glLoadIdentity(); // Reset The Projection Matrix
554 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
555 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
556 glPushMatrix(); // Store The Modelview Matrix
557 glLoadIdentity(); // Reset The Modelview Matrix
558 glTranslatef(screenwidth/2,screenheight/2,0);
559 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
560 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
562 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
564 //glScalef(.25,.25,.25);
566 glTexCoord2f(0+.2,0+.8);
567 glVertex3f(-1, -1, 0.0f);
568 glTexCoord2f(1+.2,0+.8);
569 glVertex3f(1, -1, 0.0f);
570 glTexCoord2f(1+.2,1+.8);
571 glVertex3f(1, 1, 0.0f);
572 glTexCoord2f(0+.2,1+.8);
573 glVertex3f(-1, 1, 0.0f);
576 glDisable(GL_TEXTURE_2D);
577 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
578 glPopMatrix(); // Restore The Old Projection Matrix
579 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
580 glPopMatrix(); // Restore The Old Projection Matrix
586 glEnable(GL_TEXTURE_2D);
587 static char string[256]="";
588 sprintf (string, "LOADING... %d%",(int)loadprogress);
590 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
591 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
592 text.glPrint(280,125,string,1,1,640,480);
596 if(flashamount>1)flashamount=1;
597 if(flashdelay<=0)flashamount-=multiplier;
599 if(flashamount<0)flashamount=0;
600 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
601 glDisable(GL_CULL_FACE);
602 glDisable(GL_LIGHTING);
603 glDisable(GL_TEXTURE_2D);
605 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
606 glPushMatrix(); // Store The Projection Matrix
607 glLoadIdentity(); // Reset The Projection Matrix
608 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
609 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
610 glPushMatrix(); // Store The Modelview Matrix
611 glLoadIdentity(); // Reset The Modelview Matrix
612 glScalef(screenwidth,screenheight,1);
613 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
615 glColor4f(flashr,flashg,flashb,flashamount);
617 glVertex3f(0, 0, 0.0f);
618 glVertex3f(256, 0, 0.0f);
619 glVertex3f(256, 256, 0.0f);
620 glVertex3f(0, 256, 0.0f);
622 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
623 glPopMatrix(); // Restore The Old Projection Matrix
624 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
625 glPopMatrix(); // Restore The Old Projection Matrix
626 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
627 glEnable(GL_CULL_FACE);
637 void Game::FadeLoadingScreen(float howmuch)
639 static float loadprogress,minprogress,maxprogress;
644 glClearColor(0,0,0,1);
645 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
647 loadprogress=howmuch;
649 //loadprogress=abs(Random()%100);
653 //glEnable(GL_TEXTURE_2D);
654 glDisable(GL_TEXTURE_2D);
655 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
656 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
657 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
658 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
659 glDisable(GL_CULL_FACE);
660 glDisable(GL_LIGHTING);
662 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
663 glPushMatrix(); // Store The Projection Matrix
664 glLoadIdentity(); // Reset The Projection Matrix
665 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
666 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
667 glPushMatrix(); // Store The Modelview Matrix
668 glLoadIdentity(); // Reset The Modelview Matrix
669 glTranslatef(screenwidth/2,screenheight/2,0);
670 glScalef((float)screenwidth/2,(float)screenheight/2,1);
671 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
673 glColor4f(loadprogress/100,0,0,1);
674 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
675 if(loadscreencolor==1)glColor4f(1,0,0,1);
676 if(loadscreencolor==2)glColor4f(0,1,0,1);
677 if(loadscreencolor==3)glColor4f(0,0,1,1);
678 if(loadscreencolor==4)glColor4f(1,1,0,1);
679 if(loadscreencolor==5)glColor4f(1,0,1,1);
682 //glScalef(.25,.25,.25);
685 glVertex3f(-1, -1, 0.0f);
687 glVertex3f(1, -1, 0.0f);
689 glVertex3f(1, 1, 0.0f);
691 glVertex3f(-1, 1, 0.0f);
694 glDisable(GL_TEXTURE_2D);
695 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
696 glPopMatrix(); // Restore The Old Projection Matrix
697 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
698 glPopMatrix(); // Restore The Old Projection Matrix
703 glEnable(GL_TEXTURE_2D);
704 static char string[256]="";
705 sprintf (string, "LOADING... %d%",(int)loadprogress);
707 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
708 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
709 text.glPrint(280,125,string,1,1,640,480);
716 void Game::InitGame()
719 ProcessSerialNumber PSN;
720 ProcessInfoRec pinfo;
723 /* set up process serial number */
724 PSN.highLongOfPSN = 0;
725 PSN.lowLongOfPSN = kCurrentProcess;
726 /* set up info block */
727 pinfo.processInfoLength = sizeof(pinfo);
728 pinfo.processName = NULL;
729 pinfo.processAppSpec = &pspec;
730 /* grab the vrefnum and directory */
731 err = GetProcessInformation(&PSN, &pinfo);
733 vRefNum = pspec.vRefNum;
744 numchallengelevels=14;
746 accountactive=Account::loadFile(":Data:Users");
752 whichjointstartarray[0]=righthip;
753 whichjointendarray[0]=rightfoot;
755 whichjointstartarray[1]=righthip;
756 whichjointendarray[1]=rightankle;
758 whichjointstartarray[2]=righthip;
759 whichjointendarray[2]=rightknee;
761 whichjointstartarray[3]=rightknee;
762 whichjointendarray[3]=rightankle;
764 whichjointstartarray[4]=rightankle;
765 whichjointendarray[4]=rightfoot;
767 whichjointstartarray[5]=lefthip;
768 whichjointendarray[5]=leftfoot;
770 whichjointstartarray[6]=lefthip;
771 whichjointendarray[6]=leftankle;
773 whichjointstartarray[7]=lefthip;
774 whichjointendarray[7]=leftknee;
776 whichjointstartarray[8]=leftknee;
777 whichjointendarray[8]=leftankle;
779 whichjointstartarray[9]=leftankle;
780 whichjointendarray[9]=leftfoot;
782 whichjointstartarray[10]=abdomen;
783 whichjointendarray[10]=rightshoulder;
785 whichjointstartarray[11]=abdomen;
786 whichjointendarray[11]=rightelbow;
788 whichjointstartarray[12]=abdomen;
789 whichjointendarray[12]=rightwrist;
791 whichjointstartarray[13]=abdomen;
792 whichjointendarray[13]=righthand;
794 whichjointstartarray[14]=rightshoulder;
795 whichjointendarray[14]=rightelbow;
797 whichjointstartarray[15]=rightelbow;
798 whichjointendarray[15]=rightwrist;
800 whichjointstartarray[16]=rightwrist;
801 whichjointendarray[16]=righthand;
803 whichjointstartarray[17]=abdomen;
804 whichjointendarray[17]=leftshoulder;
806 whichjointstartarray[18]=abdomen;
807 whichjointendarray[18]=leftelbow;
809 whichjointstartarray[19]=abdomen;
810 whichjointendarray[19]=leftwrist;
812 whichjointstartarray[20]=abdomen;
813 whichjointendarray[20]=lefthand;
815 whichjointstartarray[21]=leftshoulder;
816 whichjointendarray[21]=leftelbow;
818 whichjointstartarray[22]=leftelbow;
819 whichjointendarray[22]=leftwrist;
821 whichjointstartarray[23]=leftwrist;
822 whichjointendarray[23]=lefthand;
824 whichjointstartarray[24]=abdomen;
825 whichjointendarray[24]=neck;
827 whichjointstartarray[25]=neck;
828 whichjointendarray[25]=head;
830 FadeLoadingScreen(0);
834 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
836 int temptexdetail=texdetail;
838 text.LoadFontTexture(":Data:Textures:Font.png");
840 texdetail=temptexdetail;
842 FadeLoadingScreen(10);
858 memset(channels, 0xff, sizeof(channels));
859 for (int it = 0; it < 20; ++it)
864 LOG("Initializing sound system...");
869 extern bool cmdline(const char *cmd);
870 unsigned char rc = 0;
871 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
872 if (cmdline("forceoss")) // ...but let user override that.
873 output = OPENAL_OUTPUT_OSS;
874 else if (cmdline("nosound"))
875 output = OPENAL_OUTPUT_NOSOUND;
877 OPENAL_SetOutput(output);
878 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
880 // if we tried ALSA and failed, fall back to OSS.
881 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
884 output = OPENAL_OUTPUT_OSS;
885 OPENAL_SetOutput(output);
886 rc = OPENAL_Init(44100, 32, 0);
893 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
894 OPENAL_SetOutput(output);
895 rc = OPENAL_Init(44100, 32, 0);
898 OPENAL_Init(44100, 32, 0);
901 OPENAL_SetSFXMasterVolume((int)(volume*255));
903 strm[stream_music3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:music3.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=0;}
904 OPENAL_Stream_SetMode(strm[stream_music3], OPENAL_LOOP_NORMAL);
907 // PlaySoundEx( stream_music3, strm[stream_music3], NULL, true);
908 PlayStreamEx(stream_music3, strm[stream_music3], 0, true);
909 OPENAL_SetPaused(channels[stream_music3], false);
910 OPENAL_SetVolume(channels[stream_music3], 256);
913 FadeLoadingScreen(20);
916 strm[stream_wind] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:wind.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
917 OPENAL_Stream_SetMode(strm[stream_wind], OPENAL_LOOP_NORMAL);
919 FadeLoadingScreen(30);
921 strm[stream_desertambient] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:desertambient.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
922 OPENAL_Stream_SetMode(strm[stream_desertambient], OPENAL_LOOP_NORMAL);
925 FadeLoadingScreen(40);
927 strm[stream_firesound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:fire.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=5;}
928 OPENAL_Stream_SetMode(strm[stream_firesound], OPENAL_LOOP_NORMAL);
930 FadeLoadingScreen(50);
933 strm[stream_music1grass] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:music1grass.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=1;}
934 OPENAL_Stream_SetMode(strm[stream_music1grass], OPENAL_LOOP_NORMAL);
936 strm[stream_music1snow] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:music1snow.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=2;}
937 OPENAL_Stream_SetMode(strm[stream_music1snow], OPENAL_LOOP_NORMAL);
939 FadeLoadingScreen(60);
941 strm[stream_music1desert] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:music1desert.mp3"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=3;}
942 OPENAL_Stream_SetMode(strm[stream_music1desert], OPENAL_LOOP_NORMAL);
944 FadeLoadingScreen(80);
945 strm[stream_music2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:music2.ogg"), OPENAL_2D, 0, 0); if(visibleloading){LoadingScreen(); loadscreencolor=4;}
946 OPENAL_Stream_SetMode(strm[stream_music2], OPENAL_LOOP_NORMAL);
951 FadeLoadingScreen(90);
954 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
956 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
957 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
958 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
960 temptexdetail=texdetail;
961 if(texdetail>2)texdetail=2;
962 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
963 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
964 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
965 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
966 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
967 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
968 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
969 texdetail=temptexdetail;
974 FadeLoadingScreen(95);
985 newscreenwidth=screenwidth;
986 newscreenheight=screenheight;
990 void Game::LoadStuff()
992 static float temptexdetail;
993 static float viewdistdetail;
994 static int i,j,texsize;
1001 /*musicvolume[3]=512;
1002 PlaySoundEx( music4, samp[music4], NULL, true);
1003 OPENAL_SetPaused(channels[music4], false);
1004 OPENAL_SetVolume(channels[music4], 512);
1010 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
1012 for(i=0;i<maxplayers;i++)
1014 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
1016 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
1018 player[i].skeleton.drawmodel.textureptr=0;;
1021 //temptexdetail=texdetail;
1024 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
1025 //texdetail=temptexdetail;
1027 temptexdetail=texdetail;
1029 text.LoadFontTexture(":Data:Textures:Font.png");
1031 texdetail=temptexdetail;
1036 viewdistance=50*megascale*viewdistdetail;
1056 realtexdetail=texdetail;
1059 if(texdetail<1)texdetail=1;
1060 realtexdetail=texdetail*4;
1066 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
1068 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
1070 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1074 LOG("Loading weapon data...");
1076 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1077 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1078 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1079 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1080 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1081 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1082 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1084 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1085 weapons.throwingknifemodel.Scale(.001,.001,.001);
1086 //weapons.throwingknifemodel.Rotate(0,0,-90);
1087 weapons.throwingknifemodel.Rotate(90,0,0);
1088 weapons.throwingknifemodel.Rotate(0,90,0);
1089 weapons.throwingknifemodel.flat=0;
1090 weapons.throwingknifemodel.CalculateNormals(1);
1091 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1093 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1094 weapons.swordmodel.Scale(.001,.001,.001);
1095 //weapons.swordmodel.Rotate(0,0,-90);
1096 weapons.swordmodel.Rotate(90,0,0);
1097 weapons.swordmodel.Rotate(0,90,0);
1098 weapons.swordmodel.Rotate(0,0,90);
1099 weapons.swordmodel.flat=1;
1100 weapons.swordmodel.CalculateNormals(1);
1101 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1103 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1104 weapons.staffmodel.Scale(.005,.005,.005);
1105 //weapons.staffmodel.Rotate(0,0,-90);
1106 weapons.staffmodel.Rotate(90,0,0);
1107 weapons.staffmodel.Rotate(0,90,0);
1108 weapons.staffmodel.Rotate(0,0,90);
1109 weapons.staffmodel.flat=1;
1110 weapons.staffmodel.CalculateNormals(1);
1111 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1113 //temptexdetail=texdetail;
1114 //if(texdetail>4)texdetail=4;
1115 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1117 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1119 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1121 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1124 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1126 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1128 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1130 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1132 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1134 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1136 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1138 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1139 //texdetail=temptexdetail;
1140 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1144 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1146 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1149 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1152 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1153 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1154 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1155 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1156 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1157 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1158 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1159 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1160 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1161 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1162 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1166 ReSizeGLScene(90,.01);
1173 if(detail)kTextureSize=1024;
1174 if(detail==1)kTextureSize=512;
1175 if(detail==0)kTextureSize=256;
1178 //drawmode=motionblurmode;
1180 //Set up distant light
1184 light.ambient[0]=.2;
1185 light.ambient[1]=.2;
1186 light.ambient[2]=.24;
1189 light.location.z=-.2;
1190 Normalise(&light.location);
1200 texscale=.2/megascale/viewdistdetail;
1201 terrain.scale=3*megascale*terraindetail*viewdistdetail;
1203 viewer.x=terrain.size/2*terrain.scale;
1204 viewer.z=terrain.size/2*terrain.scale;
1206 hawk.load((char *)":Data:Models:hawk.solid",1);
1207 hawk.Scale(.03,.03,.03);
1208 hawk.Rotate(90,1,1);
1209 hawk.CalculateNormals(0);
1210 hawk.ScaleNormals(-1,-1,-1);
1211 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1212 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1213 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1216 eye.load((char *)":Data:Models:eye.solid",1);
1217 eye.Scale(.03,.03,.03);
1218 eye.CalculateNormals(0);
1220 cornea.load((char *)":Data:Models:cornea.solid",1);
1221 cornea.Scale(.03,.03,.03);
1222 cornea.CalculateNormals(0);
1224 iris.load((char *)":Data:Models:iris.solid",1);
1225 iris.Scale(.03,.03,.03);
1226 iris.CalculateNormals(0);
1228 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1229 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1237 //if(targetlevel!=7)
1238 Loadlevel(targetlevel);
1241 rabbitcoords=player[0].coords;
1242 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1244 loadAllAnimations();
1245 //Fix knife stab, too lazy to do it manually
1249 for(i=0;i<player[0].skeleton.num_joints;i++){
1250 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1251 animation[knifesneakattackanim].position[i][j]+=moveamount;
1258 for(i=0;i<player[0].skeleton.num_joints;i++){
1259 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1260 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1267 for(i=0;i<player[0].skeleton.num_joints;i++){
1268 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1269 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1270 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1271 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1273 animation[dead1anim].speed[0]=0.001;
1274 animation[dead2anim].speed[0]=0.001;
1275 animation[dead3anim].speed[0]=0.001;
1276 animation[dead4anim].speed[0]=0.001;
1278 animation[dead1anim].speed[1]=0.001;
1279 animation[dead2anim].speed[1]=0.001;
1280 animation[dead3anim].speed[1]=0.001;
1281 animation[dead4anim].speed[1]=0.001;
1283 for(i=0;i<player[0].skeleton.num_joints;i++){
1284 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1285 animation[swordsneakattackanim].position[i][j]+=moveamount;
1290 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1291 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1297 for(i=0;i<player[0].skeleton.num_joints;i++){
1298 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1299 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1303 for(i=0;i<player[0].skeleton.num_joints;i++){
1304 for(j=0;j<animation[sleepanim].numframes;j++){
1305 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1311 temptexdetail=texdetail;
1313 texdetail=temptexdetail;
1320 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1322 glGenTextures( 1, &screentexture );
1323 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1326 glEnable(GL_TEXTURE_2D);
1327 glBindTexture( GL_TEXTURE_2D, screentexture);
1328 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1329 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1331 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1337 /*PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1338 OPENAL_SetVolume(channels[consolesuccesssound], 256);
1339 OPENAL_SetPaused(channels[consolesuccesssound], false);
1342 float gLoc[3]={0,0,0};
1343 float vel[3]={0,0,0};
1344 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1345 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1346 OPENAL_SetVolume(channels[fireendsound], 256);
1347 OPENAL_SetPaused(channels[fireendsound], false);