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 "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
104 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
106 void LOG(const std::string &fmt, ...)
108 // !!! FIXME: write me.
112 Game::TextureList Game::textures;
121 accountactive->endGame();
125 Account::saveFile(":Data:Users", accountactive);
127 TexIter it = textures.begin();
128 for (; it != textures.end(); ++it)
130 if (glIsTexture(it->second))
131 glDeleteTextures(1, &it->second);
135 LOG("Shutting down sound system...");
137 OPENAL_StopSound(OPENAL_ALL);
139 // this is causing problems on Linux, but we'll force an _exit() a little
140 // later in the shutdown process. --ryan.
143 for (i=0; i < sounds_count; ++i)
145 OPENAL_Sample_Free(samp[i]);
158 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
164 LOG(std::string("Loading texture...") + fileName);
166 // Fix filename so that is os appropreate
167 char * fixedFN = ConvertFileName(fileName);
169 unsigned char fileNamep[256];
170 CopyCStringToPascal(fixedFN, fileNamep);
172 upload_image( fileNamep ,hasalpha);
174 // std::string fname(fileName);
175 // std::transform(fname.begin(), fname.end(), tolower);
176 // TexIter it = textures.find(fname);
180 //if(textures.end() == it)
183 if ( texture.bpp == 24 )
188 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
191 glGenTextures( 1, textureid );
192 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
194 glBindTexture( GL_TEXTURE_2D, *textureid);
195 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
196 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
197 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
198 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
200 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
204 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
212 LOG(std::string("Loading texture (S)...") + fileName);
215 unsigned char fileNamep[256];
216 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
218 upload_image( fileNamep ,0);
219 //LoadTGA( fileName );
221 // std::string fname(fileName);
222 // std::transform(fname.begin(), fname.end(), tolower);
223 // TexIter it = textures.find(fname);
227 //if(textures.end() == it)
229 bytesPerPixel=texture.bpp/8;
232 if ( texture.bpp == 24 )
237 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
239 if(!*textureid)glGenTextures( 1, textureid );
240 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
242 glBindTexture( GL_TEXTURE_2D, *textureid);
243 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
244 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
245 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
246 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
249 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
250 if((i+1)%4||type==GL_RGB){
251 array[tempnum]=texture.data[i];
256 *skinsize=texture.sizeX;
258 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
260 // textures.insert(std::make_pair(fname, *textureid));
264 // *textureid = it->second;
268 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
275 LOG(std::string("Loading (S)...") + fileName);
278 float temptexdetail=texdetail;
280 //upload_image( fileName );
281 //LoadTGA( fileName );
283 // Converting file to something os specific
284 char * fixedFN = ConvertFileName(fileName);
287 unsigned char fileNamep[256];
288 CopyCStringToPascal(fixedFN, fileNamep);
290 upload_image( fileNamep ,0);
291 texdetail=temptexdetail;
295 bytesPerPixel=texture.bpp/8;
298 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
299 if((i+1)%4||bytesPerPixel==3){
300 array[tempnum]=texture.data[i];
307 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
314 //upload_image( fileName );
315 //LoadTGA( fileName );
317 unsigned char fileNamep[256];
318 CopyCStringToPascal(fileName,fileNamep);
321 opened=upload_image( fileNamep ,1);
334 bytesPerPixel=texture.bpp/8;
338 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
339 if(bytesPerPixel==3)alphanum=255;
340 else if((i+1)%4==0)alphanum=texture.data[i];
342 if((i+1)%4||bytesPerPixel==3){
343 if((i%4)==0)texture.data[i]*=tintr;
344 if((i%4)==1)texture.data[i]*=tintg;
345 if((i%4)==2)texture.data[i]*=tintb;
346 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
356 //***************> ResizeGLScene() <******/
357 GLvoid Game::ReSizeGLScene(float fov, float pnear)
364 glViewport(0,0,screenwidth,screenheight);
366 glMatrixMode(GL_PROJECTION);
369 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
371 glMatrixMode(GL_MODELVIEW);
375 void Game::LoadingScreen()
377 static float loadprogress,minprogress,maxprogress;
378 static AbsoluteTime time = {0,0};
379 static AbsoluteTime frametime = {0,0};
380 AbsoluteTime currTime = UpTime ();
381 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
383 if (0 > deltaTime) // if negative microseconds
384 deltaTime /= -1000000.0;
385 else // else milliseconds
388 multiplier=deltaTime;
389 if(multiplier<.001)multiplier=.001;
390 if(multiplier>10)multiplier=10;
392 frametime = currTime; // reset for next time interval
397 glClearColor(0,0,0,1);
398 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
401 loadtime+=multiplier*4;
403 loadprogress=loadtime;
404 if(loadprogress>100)loadprogress=100;
406 //loadprogress=abs(Random()%100);
410 glEnable(GL_TEXTURE_2D);
411 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
412 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
413 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
414 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
415 glDisable(GL_CULL_FACE);
416 glDisable(GL_LIGHTING);
418 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
419 glPushMatrix(); // Store The Projection Matrix
420 glLoadIdentity(); // Reset The Projection Matrix
421 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
422 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
423 glPushMatrix(); // Store The Modelview Matrix
424 glLoadIdentity(); // Reset The Modelview Matrix
425 glTranslatef(screenwidth/2,screenheight/2,0);
426 glScalef((float)screenwidth/2,(float)screenheight/2,1);
427 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
429 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
430 //glColor4f(1,1,1,1);
431 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
432 if(loadscreencolor==1)glColor4f(1,0,0,1);
433 if(loadscreencolor==2)glColor4f(0,1,0,1);
434 if(loadscreencolor==3)glColor4f(0,0,1,1);
435 if(loadscreencolor==4)glColor4f(1,1,0,1);
436 if(loadscreencolor==5)glColor4f(1,0,1,1);
439 //glScalef(.25,.25,.25);
441 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
442 glVertex3f(-1, -1, 0.0f);
443 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
444 glVertex3f(1, -1, 0.0f);
445 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
446 glVertex3f(1, 1, 0.0f);
447 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
448 glVertex3f(-1, 1, 0.0f);
453 //glScalef(.25,.25,.25);
455 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
456 glVertex3f(-1, -1, 0.0f);
457 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
458 glVertex3f(1, -1, 0.0f);
459 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
460 glVertex3f(1, 1, 0.0f);
461 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
462 glVertex3f(-1, 1, 0.0f);
465 glDisable(GL_TEXTURE_2D);
466 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
467 glPopMatrix(); // Restore The Old Projection Matrix
468 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
469 glPopMatrix(); // Restore The Old Projection Matrix
473 glEnable(GL_TEXTURE_2D);
474 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
475 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
476 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
477 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
478 glDisable(GL_CULL_FACE);
479 glDisable(GL_LIGHTING);
481 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
482 glPushMatrix(); // Store The Projection Matrix
483 glLoadIdentity(); // Reset The Projection Matrix
484 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
485 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
486 glPushMatrix(); // Store The Modelview Matrix
487 glLoadIdentity(); // Reset The Modelview Matrix
488 glTranslatef(screenwidth/2,screenheight/2,0);
489 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
490 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
492 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
493 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
494 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
495 if(loadscreencolor==1)glColor4f(1,0,0,1);
496 if(loadscreencolor==2)glColor4f(0,1,0,1);
497 if(loadscreencolor==3)glColor4f(0,0,1,1);
498 if(loadscreencolor==4)glColor4f(1,1,0,1);
499 if(loadscreencolor==5)glColor4f(1,0,1,1);
502 //glScalef(.25,.25,.25);
504 glTexCoord2f(0+.5,0+.5);
505 glVertex3f(-1, -1, 0.0f);
506 glTexCoord2f(1+.5,0+.5);
507 glVertex3f(1, -1, 0.0f);
508 glTexCoord2f(1+.5,1+.5);
509 glVertex3f(1, 1, 0.0f);
510 glTexCoord2f(0+.5,1+.5);
511 glVertex3f(-1, 1, 0.0f);
514 glDisable(GL_TEXTURE_2D);
515 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
516 glPopMatrix(); // Restore The Old Projection Matrix
517 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
518 glPopMatrix(); // Restore The Old Projection Matrix
522 glEnable(GL_TEXTURE_2D);
523 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
524 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
525 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
526 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
527 glDisable(GL_CULL_FACE);
528 glDisable(GL_LIGHTING);
530 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
531 glPushMatrix(); // Store The Projection Matrix
532 glLoadIdentity(); // Reset The Projection Matrix
533 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
534 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
535 glPushMatrix(); // Store The Modelview Matrix
536 glLoadIdentity(); // Reset The Modelview Matrix
537 glTranslatef(screenwidth/2,screenheight/2,0);
538 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
539 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
541 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
543 //glScalef(.25,.25,.25);
545 glTexCoord2f(0+.2,0+.8);
546 glVertex3f(-1, -1, 0.0f);
547 glTexCoord2f(1+.2,0+.8);
548 glVertex3f(1, -1, 0.0f);
549 glTexCoord2f(1+.2,1+.8);
550 glVertex3f(1, 1, 0.0f);
551 glTexCoord2f(0+.2,1+.8);
552 glVertex3f(-1, 1, 0.0f);
555 glDisable(GL_TEXTURE_2D);
556 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
557 glPopMatrix(); // Restore The Old Projection Matrix
558 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
559 glPopMatrix(); // Restore The Old Projection Matrix
565 glEnable(GL_TEXTURE_2D);
566 static char string[256]="";
567 sprintf (string, "LOADING... %d%",(int)loadprogress);
569 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
570 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
571 text.glPrint(280,125,string,1,1,640,480);
575 if(flashamount>1)flashamount=1;
576 if(flashdelay<=0)flashamount-=multiplier;
578 if(flashamount<0)flashamount=0;
579 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
580 glDisable(GL_CULL_FACE);
581 glDisable(GL_LIGHTING);
582 glDisable(GL_TEXTURE_2D);
584 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
585 glPushMatrix(); // Store The Projection Matrix
586 glLoadIdentity(); // Reset The Projection Matrix
587 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
588 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
589 glPushMatrix(); // Store The Modelview Matrix
590 glLoadIdentity(); // Reset The Modelview Matrix
591 glScalef(screenwidth,screenheight,1);
592 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
594 glColor4f(flashr,flashg,flashb,flashamount);
596 glVertex3f(0, 0, 0.0f);
597 glVertex3f(256, 0, 0.0f);
598 glVertex3f(256, 256, 0.0f);
599 glVertex3f(0, 256, 0.0f);
601 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
602 glPopMatrix(); // Restore The Old Projection Matrix
603 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
604 glPopMatrix(); // Restore The Old Projection Matrix
605 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
606 glEnable(GL_CULL_FACE);
616 void Game::FadeLoadingScreen(float howmuch)
618 static float loadprogress,minprogress,maxprogress;
623 glClearColor(0,0,0,1);
624 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
626 loadprogress=howmuch;
628 //loadprogress=abs(Random()%100);
632 //glEnable(GL_TEXTURE_2D);
633 glDisable(GL_TEXTURE_2D);
634 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
635 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
636 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
637 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
638 glDisable(GL_CULL_FACE);
639 glDisable(GL_LIGHTING);
641 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
642 glPushMatrix(); // Store The Projection Matrix
643 glLoadIdentity(); // Reset The Projection Matrix
644 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
645 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
646 glPushMatrix(); // Store The Modelview Matrix
647 glLoadIdentity(); // Reset The Modelview Matrix
648 glTranslatef(screenwidth/2,screenheight/2,0);
649 glScalef((float)screenwidth/2,(float)screenheight/2,1);
650 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
652 glColor4f(loadprogress/100,0,0,1);
653 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
654 if(loadscreencolor==1)glColor4f(1,0,0,1);
655 if(loadscreencolor==2)glColor4f(0,1,0,1);
656 if(loadscreencolor==3)glColor4f(0,0,1,1);
657 if(loadscreencolor==4)glColor4f(1,1,0,1);
658 if(loadscreencolor==5)glColor4f(1,0,1,1);
661 //glScalef(.25,.25,.25);
664 glVertex3f(-1, -1, 0.0f);
666 glVertex3f(1, -1, 0.0f);
668 glVertex3f(1, 1, 0.0f);
670 glVertex3f(-1, 1, 0.0f);
673 glDisable(GL_TEXTURE_2D);
674 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
675 glPopMatrix(); // Restore The Old Projection Matrix
676 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
677 glPopMatrix(); // Restore The Old Projection Matrix
682 glEnable(GL_TEXTURE_2D);
683 static char string[256]="";
684 sprintf (string, "LOADING... %d%",(int)loadprogress);
686 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
687 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
688 text.glPrint(280,125,string,1,1,640,480);
695 void Game::InitGame()
698 ProcessSerialNumber PSN;
699 ProcessInfoRec pinfo;
702 /* set up process serial number */
703 PSN.highLongOfPSN = 0;
704 PSN.lowLongOfPSN = kCurrentProcess;
705 /* set up info block */
706 pinfo.processInfoLength = sizeof(pinfo);
707 pinfo.processName = NULL;
708 pinfo.processAppSpec = &pspec;
709 /* grab the vrefnum and directory */
710 err = GetProcessInformation(&PSN, &pinfo);
712 vRefNum = pspec.vRefNum;
723 numchallengelevels=14;
725 accountactive=Account::loadFile(":Data:Users");
731 whichjointstartarray[0]=righthip;
732 whichjointendarray[0]=rightfoot;
734 whichjointstartarray[1]=righthip;
735 whichjointendarray[1]=rightankle;
737 whichjointstartarray[2]=righthip;
738 whichjointendarray[2]=rightknee;
740 whichjointstartarray[3]=rightknee;
741 whichjointendarray[3]=rightankle;
743 whichjointstartarray[4]=rightankle;
744 whichjointendarray[4]=rightfoot;
746 whichjointstartarray[5]=lefthip;
747 whichjointendarray[5]=leftfoot;
749 whichjointstartarray[6]=lefthip;
750 whichjointendarray[6]=leftankle;
752 whichjointstartarray[7]=lefthip;
753 whichjointendarray[7]=leftknee;
755 whichjointstartarray[8]=leftknee;
756 whichjointendarray[8]=leftankle;
758 whichjointstartarray[9]=leftankle;
759 whichjointendarray[9]=leftfoot;
761 whichjointstartarray[10]=abdomen;
762 whichjointendarray[10]=rightshoulder;
764 whichjointstartarray[11]=abdomen;
765 whichjointendarray[11]=rightelbow;
767 whichjointstartarray[12]=abdomen;
768 whichjointendarray[12]=rightwrist;
770 whichjointstartarray[13]=abdomen;
771 whichjointendarray[13]=righthand;
773 whichjointstartarray[14]=rightshoulder;
774 whichjointendarray[14]=rightelbow;
776 whichjointstartarray[15]=rightelbow;
777 whichjointendarray[15]=rightwrist;
779 whichjointstartarray[16]=rightwrist;
780 whichjointendarray[16]=righthand;
782 whichjointstartarray[17]=abdomen;
783 whichjointendarray[17]=leftshoulder;
785 whichjointstartarray[18]=abdomen;
786 whichjointendarray[18]=leftelbow;
788 whichjointstartarray[19]=abdomen;
789 whichjointendarray[19]=leftwrist;
791 whichjointstartarray[20]=abdomen;
792 whichjointendarray[20]=lefthand;
794 whichjointstartarray[21]=leftshoulder;
795 whichjointendarray[21]=leftelbow;
797 whichjointstartarray[22]=leftelbow;
798 whichjointendarray[22]=leftwrist;
800 whichjointstartarray[23]=leftwrist;
801 whichjointendarray[23]=lefthand;
803 whichjointstartarray[24]=abdomen;
804 whichjointendarray[24]=neck;
806 whichjointstartarray[25]=neck;
807 whichjointendarray[25]=head;
809 FadeLoadingScreen(0);
813 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
815 int temptexdetail=texdetail;
817 text.LoadFontTexture(":Data:Textures:Font.png");
819 texdetail=temptexdetail;
821 FadeLoadingScreen(10);
837 memset(channels, 0xff, sizeof(channels));
839 LOG("Initializing sound system...");
844 extern bool cmdline(const char *cmd);
845 unsigned char rc = 0;
846 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
847 if (cmdline("forceoss")) // ...but let user override that.
848 output = OPENAL_OUTPUT_OSS;
849 else if (cmdline("nosound"))
850 output = OPENAL_OUTPUT_NOSOUND;
852 OPENAL_SetOutput(output);
853 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
855 // if we tried ALSA and failed, fall back to OSS.
856 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
859 output = OPENAL_OUTPUT_OSS;
860 OPENAL_SetOutput(output);
861 rc = OPENAL_Init(44100, 32, 0);
868 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
869 OPENAL_SetOutput(output);
870 rc = OPENAL_Init(44100, 32, 0);
873 OPENAL_Init(44100, 32, 0);
876 OPENAL_SetSFXMasterVolume((int)(volume*255));
880 PlayStreamEx(stream_music3, samp[stream_music3], 0, true);
881 OPENAL_SetPaused(channels[stream_music3], false);
882 OPENAL_SetVolume(channels[stream_music3], 256);
885 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
887 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
888 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
889 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
891 temptexdetail=texdetail;
892 if(texdetail>2)texdetail=2;
893 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
894 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
895 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
896 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
897 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
898 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
899 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
900 texdetail=temptexdetail;
905 FadeLoadingScreen(95);
916 newscreenwidth=screenwidth;
917 newscreenheight=screenheight;
921 void Game::LoadStuff()
923 static float temptexdetail;
924 static float viewdistdetail;
925 static int i,j,texsize;
932 /*musicvolume[3]=512;
933 PlaySoundEx( music4, samp[music4], NULL, true);
934 OPENAL_SetPaused(channels[music4], false);
935 OPENAL_SetVolume(channels[music4], 512);
941 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
943 for(i=0;i<maxplayers;i++)
945 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
947 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
949 player[i].skeleton.drawmodel.textureptr=0;;
952 //temptexdetail=texdetail;
955 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
956 //texdetail=temptexdetail;
958 temptexdetail=texdetail;
960 text.LoadFontTexture(":Data:Textures:Font.png");
962 texdetail=temptexdetail;
967 viewdistance=50*megascale*viewdistdetail;
987 realtexdetail=texdetail;
990 if(texdetail<1)texdetail=1;
991 realtexdetail=texdetail*4;
997 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
999 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
1001 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1005 LOG("Loading weapon data...");
1007 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1008 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1009 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1010 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1011 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1012 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1013 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1015 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1016 weapons.throwingknifemodel.Scale(.001,.001,.001);
1017 //weapons.throwingknifemodel.Rotate(0,0,-90);
1018 weapons.throwingknifemodel.Rotate(90,0,0);
1019 weapons.throwingknifemodel.Rotate(0,90,0);
1020 weapons.throwingknifemodel.flat=0;
1021 weapons.throwingknifemodel.CalculateNormals(1);
1022 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1024 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1025 weapons.swordmodel.Scale(.001,.001,.001);
1026 //weapons.swordmodel.Rotate(0,0,-90);
1027 weapons.swordmodel.Rotate(90,0,0);
1028 weapons.swordmodel.Rotate(0,90,0);
1029 weapons.swordmodel.Rotate(0,0,90);
1030 weapons.swordmodel.flat=1;
1031 weapons.swordmodel.CalculateNormals(1);
1032 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1034 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1035 weapons.staffmodel.Scale(.005,.005,.005);
1036 //weapons.staffmodel.Rotate(0,0,-90);
1037 weapons.staffmodel.Rotate(90,0,0);
1038 weapons.staffmodel.Rotate(0,90,0);
1039 weapons.staffmodel.Rotate(0,0,90);
1040 weapons.staffmodel.flat=1;
1041 weapons.staffmodel.CalculateNormals(1);
1042 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1044 //temptexdetail=texdetail;
1045 //if(texdetail>4)texdetail=4;
1046 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1048 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1050 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1052 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1055 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1057 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1059 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1061 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1063 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1065 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1067 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1069 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1070 //texdetail=temptexdetail;
1071 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1075 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1077 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1080 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1083 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1084 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1085 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1086 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1087 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1088 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1089 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1090 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1091 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1092 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1093 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1097 ReSizeGLScene(90,.01);
1104 if(detail)kTextureSize=1024;
1105 if(detail==1)kTextureSize=512;
1106 if(detail==0)kTextureSize=256;
1109 //drawmode=motionblurmode;
1111 //Set up distant light
1115 light.ambient[0]=.2;
1116 light.ambient[1]=.2;
1117 light.ambient[2]=.24;
1120 light.location.z=-.2;
1121 Normalise(&light.location);
1131 texscale=.2/megascale/viewdistdetail;
1132 terrain.scale=3*megascale*terraindetail*viewdistdetail;
1134 viewer.x=terrain.size/2*terrain.scale;
1135 viewer.z=terrain.size/2*terrain.scale;
1137 hawk.load((char *)":Data:Models:hawk.solid",1);
1138 hawk.Scale(.03,.03,.03);
1139 hawk.Rotate(90,1,1);
1140 hawk.CalculateNormals(0);
1141 hawk.ScaleNormals(-1,-1,-1);
1142 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1143 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1144 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1147 eye.load((char *)":Data:Models:eye.solid",1);
1148 eye.Scale(.03,.03,.03);
1149 eye.CalculateNormals(0);
1151 cornea.load((char *)":Data:Models:cornea.solid",1);
1152 cornea.Scale(.03,.03,.03);
1153 cornea.CalculateNormals(0);
1155 iris.load((char *)":Data:Models:iris.solid",1);
1156 iris.Scale(.03,.03,.03);
1157 iris.CalculateNormals(0);
1159 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1160 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1168 //if(targetlevel!=7)
1169 Loadlevel(targetlevel);
1172 rabbitcoords=player[0].coords;
1173 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1175 loadAllAnimations();
1176 //Fix knife stab, too lazy to do it manually
1180 for(i=0;i<player[0].skeleton.num_joints;i++){
1181 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1182 animation[knifesneakattackanim].position[i][j]+=moveamount;
1189 for(i=0;i<player[0].skeleton.num_joints;i++){
1190 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1191 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1198 for(i=0;i<player[0].skeleton.num_joints;i++){
1199 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1200 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1201 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1202 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1204 animation[dead1anim].speed[0]=0.001;
1205 animation[dead2anim].speed[0]=0.001;
1206 animation[dead3anim].speed[0]=0.001;
1207 animation[dead4anim].speed[0]=0.001;
1209 animation[dead1anim].speed[1]=0.001;
1210 animation[dead2anim].speed[1]=0.001;
1211 animation[dead3anim].speed[1]=0.001;
1212 animation[dead4anim].speed[1]=0.001;
1214 for(i=0;i<player[0].skeleton.num_joints;i++){
1215 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1216 animation[swordsneakattackanim].position[i][j]+=moveamount;
1221 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1222 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1228 for(i=0;i<player[0].skeleton.num_joints;i++){
1229 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1230 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1234 for(i=0;i<player[0].skeleton.num_joints;i++){
1235 for(j=0;j<animation[sleepanim].numframes;j++){
1236 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1242 temptexdetail=texdetail;
1244 texdetail=temptexdetail;
1251 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1253 glGenTextures( 1, &screentexture );
1254 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1257 glEnable(GL_TEXTURE_2D);
1258 glBindTexture( GL_TEXTURE_2D, screentexture);
1259 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1260 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1262 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1266 float gLoc[3]={0,0,0};
1267 float vel[3]={0,0,0};
1268 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1269 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1270 OPENAL_SetVolume(channels[fireendsound], 256);
1271 OPENAL_SetPaused(channels[fireendsound], false);