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 int environment;
55 extern bool ambientsound;
56 extern float multiplier;
57 extern int netdatanew;
59 extern bool stillloading;
60 extern TGAImageRec texture;
64 extern int oldmainmenu;
65 extern bool visibleloading;
66 extern int loadscreencolor;
67 extern float flashamount,flashr,flashg,flashb;
68 extern int flashdelay;
69 extern int whichjointstartarray[26];
70 extern int whichjointendarray[26];
71 extern int difficulty;
72 extern float tintr,tintg,tintb;
73 extern float slomospeed;
74 extern char mapname[256];
75 extern bool gamestarted;
77 extern int numdialogues;
78 extern int numdialogueboxes[20];
79 extern int dialoguetype[20];
80 extern int dialogueboxlocation[20][20];
81 extern float dialogueboxcolor[20][20][3];
82 extern int dialogueboxsound[20][20];
83 extern char dialoguetext[20][20][128];
84 extern char dialoguename[20][20][64];
85 extern XYZ dialoguecamera[20][20];
86 extern float dialoguecamerarotation[20][20];
87 extern float dialoguecamerarotation2[20][20];
88 extern int indialogue;
89 extern int whichdialogue;
90 extern float dialoguetime;
92 extern float accountcampaignhighscore[10];
93 extern float accountcampaignfasttime[10];
94 extern float accountcampaignscore[10];
95 extern float accountcampaigntime[10];
97 extern int accountcampaignchoicesmade[10];
98 extern int accountcampaignchoices[10][5000];
100 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
102 void LOG(const std::string &fmt, ...)
104 // !!! FIXME: write me.
108 Game::TextureList Game::textures;
117 accountactive->endGame();
121 Account::saveFile(":Data:Users", accountactive);
123 TexIter it = textures.begin();
124 for (; it != textures.end(); ++it)
126 if (glIsTexture(it->second))
127 glDeleteTextures(1, &it->second);
131 LOG("Shutting down sound system...");
133 OPENAL_StopSound(OPENAL_ALL);
135 // this is causing problems on Linux, but we'll force an _exit() a little
136 // later in the shutdown process. --ryan.
139 for (i=0; i < sounds_count; ++i)
141 OPENAL_Sample_Free(samp[i]);
154 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
160 LOG(std::string("Loading texture...") + fileName);
162 // Fix filename so that is os appropreate
163 char * fixedFN = ConvertFileName(fileName);
165 unsigned char fileNamep[256];
166 CopyCStringToPascal(fixedFN, fileNamep);
168 upload_image( fileNamep ,hasalpha);
170 // std::string fname(fileName);
171 // std::transform(fname.begin(), fname.end(), tolower);
172 // TexIter it = textures.find(fname);
176 //if(textures.end() == it)
179 if ( texture.bpp == 24 )
184 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
187 glGenTextures( 1, textureid );
188 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
190 glBindTexture( GL_TEXTURE_2D, *textureid);
191 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
192 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
193 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
194 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
196 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
200 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
208 LOG(std::string("Loading texture (S)...") + fileName);
211 unsigned char fileNamep[256];
212 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
214 upload_image( fileNamep ,0);
215 //LoadTGA( fileName );
217 // std::string fname(fileName);
218 // std::transform(fname.begin(), fname.end(), tolower);
219 // TexIter it = textures.find(fname);
223 //if(textures.end() == it)
225 bytesPerPixel=texture.bpp/8;
228 if ( texture.bpp == 24 )
233 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
235 if(!*textureid)glGenTextures( 1, textureid );
236 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
238 glBindTexture( GL_TEXTURE_2D, *textureid);
239 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
240 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
241 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
242 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
245 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
246 if((i+1)%4||type==GL_RGB){
247 array[tempnum]=texture.data[i];
252 *skinsize=texture.sizeX;
254 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
256 // textures.insert(std::make_pair(fname, *textureid));
260 // *textureid = it->second;
264 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
271 LOG(std::string("Loading (S)...") + fileName);
274 float temptexdetail=texdetail;
276 //upload_image( fileName );
277 //LoadTGA( fileName );
279 // Converting file to something os specific
280 char * fixedFN = ConvertFileName(fileName);
283 unsigned char fileNamep[256];
284 CopyCStringToPascal(fixedFN, fileNamep);
286 upload_image( fileNamep ,0);
287 texdetail=temptexdetail;
291 bytesPerPixel=texture.bpp/8;
294 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
295 if((i+1)%4||bytesPerPixel==3){
296 array[tempnum]=texture.data[i];
303 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
310 //upload_image( fileName );
311 //LoadTGA( fileName );
313 unsigned char fileNamep[256];
314 CopyCStringToPascal(fileName,fileNamep);
317 opened=upload_image( fileNamep ,1);
330 bytesPerPixel=texture.bpp/8;
334 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
335 if(bytesPerPixel==3)alphanum=255;
336 else if((i+1)%4==0)alphanum=texture.data[i];
338 if((i+1)%4||bytesPerPixel==3){
339 if((i%4)==0)texture.data[i]*=tintr;
340 if((i%4)==1)texture.data[i]*=tintg;
341 if((i%4)==2)texture.data[i]*=tintb;
342 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
352 //***************> ResizeGLScene() <******/
353 GLvoid Game::ReSizeGLScene(float fov, float pnear)
360 glViewport(0,0,screenwidth,screenheight);
362 glMatrixMode(GL_PROJECTION);
365 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
367 glMatrixMode(GL_MODELVIEW);
371 void Game::LoadingScreen()
373 static float loadprogress,minprogress,maxprogress;
374 static AbsoluteTime time = {0,0};
375 static AbsoluteTime frametime = {0,0};
376 AbsoluteTime currTime = UpTime ();
377 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
379 if (0 > deltaTime) // if negative microseconds
380 deltaTime /= -1000000.0;
381 else // else milliseconds
384 multiplier=deltaTime;
385 if(multiplier<.001)multiplier=.001;
386 if(multiplier>10)multiplier=10;
388 frametime = currTime; // reset for next time interval
393 glClearColor(0,0,0,1);
394 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
397 loadtime+=multiplier*4;
399 loadprogress=loadtime;
400 if(loadprogress>100)loadprogress=100;
402 //loadprogress=abs(Random()%100);
406 glEnable(GL_TEXTURE_2D);
407 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
408 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
409 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
410 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
411 glDisable(GL_CULL_FACE);
412 glDisable(GL_LIGHTING);
414 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
415 glPushMatrix(); // Store The Projection Matrix
416 glLoadIdentity(); // Reset The Projection Matrix
417 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
418 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
419 glPushMatrix(); // Store The Modelview Matrix
420 glLoadIdentity(); // Reset The Modelview Matrix
421 glTranslatef(screenwidth/2,screenheight/2,0);
422 glScalef((float)screenwidth/2,(float)screenheight/2,1);
423 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
425 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
426 //glColor4f(1,1,1,1);
427 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
428 if(loadscreencolor==1)glColor4f(1,0,0,1);
429 if(loadscreencolor==2)glColor4f(0,1,0,1);
430 if(loadscreencolor==3)glColor4f(0,0,1,1);
431 if(loadscreencolor==4)glColor4f(1,1,0,1);
432 if(loadscreencolor==5)glColor4f(1,0,1,1);
435 //glScalef(.25,.25,.25);
437 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
438 glVertex3f(-1, -1, 0.0f);
439 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
440 glVertex3f(1, -1, 0.0f);
441 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
442 glVertex3f(1, 1, 0.0f);
443 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
444 glVertex3f(-1, 1, 0.0f);
449 //glScalef(.25,.25,.25);
451 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
452 glVertex3f(-1, -1, 0.0f);
453 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
454 glVertex3f(1, -1, 0.0f);
455 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
456 glVertex3f(1, 1, 0.0f);
457 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
458 glVertex3f(-1, 1, 0.0f);
461 glDisable(GL_TEXTURE_2D);
462 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
463 glPopMatrix(); // Restore The Old Projection Matrix
464 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
465 glPopMatrix(); // Restore The Old Projection Matrix
469 glEnable(GL_TEXTURE_2D);
470 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
471 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
472 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
473 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
474 glDisable(GL_CULL_FACE);
475 glDisable(GL_LIGHTING);
477 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
478 glPushMatrix(); // Store The Projection Matrix
479 glLoadIdentity(); // Reset The Projection Matrix
480 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
481 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
482 glPushMatrix(); // Store The Modelview Matrix
483 glLoadIdentity(); // Reset The Modelview Matrix
484 glTranslatef(screenwidth/2,screenheight/2,0);
485 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
486 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
488 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
489 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
490 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
491 if(loadscreencolor==1)glColor4f(1,0,0,1);
492 if(loadscreencolor==2)glColor4f(0,1,0,1);
493 if(loadscreencolor==3)glColor4f(0,0,1,1);
494 if(loadscreencolor==4)glColor4f(1,1,0,1);
495 if(loadscreencolor==5)glColor4f(1,0,1,1);
498 //glScalef(.25,.25,.25);
500 glTexCoord2f(0+.5,0+.5);
501 glVertex3f(-1, -1, 0.0f);
502 glTexCoord2f(1+.5,0+.5);
503 glVertex3f(1, -1, 0.0f);
504 glTexCoord2f(1+.5,1+.5);
505 glVertex3f(1, 1, 0.0f);
506 glTexCoord2f(0+.5,1+.5);
507 glVertex3f(-1, 1, 0.0f);
510 glDisable(GL_TEXTURE_2D);
511 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
512 glPopMatrix(); // Restore The Old Projection Matrix
513 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
514 glPopMatrix(); // Restore The Old Projection Matrix
518 glEnable(GL_TEXTURE_2D);
519 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
520 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
521 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
522 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
523 glDisable(GL_CULL_FACE);
524 glDisable(GL_LIGHTING);
526 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
527 glPushMatrix(); // Store The Projection Matrix
528 glLoadIdentity(); // Reset The Projection Matrix
529 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
530 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
531 glPushMatrix(); // Store The Modelview Matrix
532 glLoadIdentity(); // Reset The Modelview Matrix
533 glTranslatef(screenwidth/2,screenheight/2,0);
534 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
535 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
537 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
539 //glScalef(.25,.25,.25);
541 glTexCoord2f(0+.2,0+.8);
542 glVertex3f(-1, -1, 0.0f);
543 glTexCoord2f(1+.2,0+.8);
544 glVertex3f(1, -1, 0.0f);
545 glTexCoord2f(1+.2,1+.8);
546 glVertex3f(1, 1, 0.0f);
547 glTexCoord2f(0+.2,1+.8);
548 glVertex3f(-1, 1, 0.0f);
551 glDisable(GL_TEXTURE_2D);
552 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
553 glPopMatrix(); // Restore The Old Projection Matrix
554 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
555 glPopMatrix(); // Restore The Old Projection Matrix
561 glEnable(GL_TEXTURE_2D);
562 static char string[256]="";
563 sprintf (string, "LOADING... %d%",(int)loadprogress);
565 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
566 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
567 text.glPrint(280,125,string,1,1,640,480);
571 if(flashamount>1)flashamount=1;
572 if(flashdelay<=0)flashamount-=multiplier;
574 if(flashamount<0)flashamount=0;
575 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
576 glDisable(GL_CULL_FACE);
577 glDisable(GL_LIGHTING);
578 glDisable(GL_TEXTURE_2D);
580 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
581 glPushMatrix(); // Store The Projection Matrix
582 glLoadIdentity(); // Reset The Projection Matrix
583 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
584 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
585 glPushMatrix(); // Store The Modelview Matrix
586 glLoadIdentity(); // Reset The Modelview Matrix
587 glScalef(screenwidth,screenheight,1);
588 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
590 glColor4f(flashr,flashg,flashb,flashamount);
592 glVertex3f(0, 0, 0.0f);
593 glVertex3f(256, 0, 0.0f);
594 glVertex3f(256, 256, 0.0f);
595 glVertex3f(0, 256, 0.0f);
597 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
598 glPopMatrix(); // Restore The Old Projection Matrix
599 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
600 glPopMatrix(); // Restore The Old Projection Matrix
601 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
602 glEnable(GL_CULL_FACE);
612 void Game::FadeLoadingScreen(float howmuch)
614 static float loadprogress,minprogress,maxprogress;
619 glClearColor(0,0,0,1);
620 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
622 loadprogress=howmuch;
624 //loadprogress=abs(Random()%100);
628 //glEnable(GL_TEXTURE_2D);
629 glDisable(GL_TEXTURE_2D);
630 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
631 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
632 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
633 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
634 glDisable(GL_CULL_FACE);
635 glDisable(GL_LIGHTING);
637 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
638 glPushMatrix(); // Store The Projection Matrix
639 glLoadIdentity(); // Reset The Projection Matrix
640 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
641 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
642 glPushMatrix(); // Store The Modelview Matrix
643 glLoadIdentity(); // Reset The Modelview Matrix
644 glTranslatef(screenwidth/2,screenheight/2,0);
645 glScalef((float)screenwidth/2,(float)screenheight/2,1);
646 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
648 glColor4f(loadprogress/100,0,0,1);
649 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
650 if(loadscreencolor==1)glColor4f(1,0,0,1);
651 if(loadscreencolor==2)glColor4f(0,1,0,1);
652 if(loadscreencolor==3)glColor4f(0,0,1,1);
653 if(loadscreencolor==4)glColor4f(1,1,0,1);
654 if(loadscreencolor==5)glColor4f(1,0,1,1);
657 //glScalef(.25,.25,.25);
660 glVertex3f(-1, -1, 0.0f);
662 glVertex3f(1, -1, 0.0f);
664 glVertex3f(1, 1, 0.0f);
666 glVertex3f(-1, 1, 0.0f);
669 glDisable(GL_TEXTURE_2D);
670 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
671 glPopMatrix(); // Restore The Old Projection Matrix
672 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
673 glPopMatrix(); // Restore The Old Projection Matrix
678 glEnable(GL_TEXTURE_2D);
679 static char string[256]="";
680 sprintf (string, "LOADING... %d%",(int)loadprogress);
682 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
683 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
684 text.glPrint(280,125,string,1,1,640,480);
691 void Game::InitGame()
694 ProcessSerialNumber PSN;
695 ProcessInfoRec pinfo;
698 /* set up process serial number */
699 PSN.highLongOfPSN = 0;
700 PSN.lowLongOfPSN = kCurrentProcess;
701 /* set up info block */
702 pinfo.processInfoLength = sizeof(pinfo);
703 pinfo.processName = NULL;
704 pinfo.processAppSpec = &pspec;
705 /* grab the vrefnum and directory */
706 err = GetProcessInformation(&PSN, &pinfo);
708 vRefNum = pspec.vRefNum;
719 numchallengelevels=14;
721 accountactive=Account::loadFile(":Data:Users");
727 whichjointstartarray[0]=righthip;
728 whichjointendarray[0]=rightfoot;
730 whichjointstartarray[1]=righthip;
731 whichjointendarray[1]=rightankle;
733 whichjointstartarray[2]=righthip;
734 whichjointendarray[2]=rightknee;
736 whichjointstartarray[3]=rightknee;
737 whichjointendarray[3]=rightankle;
739 whichjointstartarray[4]=rightankle;
740 whichjointendarray[4]=rightfoot;
742 whichjointstartarray[5]=lefthip;
743 whichjointendarray[5]=leftfoot;
745 whichjointstartarray[6]=lefthip;
746 whichjointendarray[6]=leftankle;
748 whichjointstartarray[7]=lefthip;
749 whichjointendarray[7]=leftknee;
751 whichjointstartarray[8]=leftknee;
752 whichjointendarray[8]=leftankle;
754 whichjointstartarray[9]=leftankle;
755 whichjointendarray[9]=leftfoot;
757 whichjointstartarray[10]=abdomen;
758 whichjointendarray[10]=rightshoulder;
760 whichjointstartarray[11]=abdomen;
761 whichjointendarray[11]=rightelbow;
763 whichjointstartarray[12]=abdomen;
764 whichjointendarray[12]=rightwrist;
766 whichjointstartarray[13]=abdomen;
767 whichjointendarray[13]=righthand;
769 whichjointstartarray[14]=rightshoulder;
770 whichjointendarray[14]=rightelbow;
772 whichjointstartarray[15]=rightelbow;
773 whichjointendarray[15]=rightwrist;
775 whichjointstartarray[16]=rightwrist;
776 whichjointendarray[16]=righthand;
778 whichjointstartarray[17]=abdomen;
779 whichjointendarray[17]=leftshoulder;
781 whichjointstartarray[18]=abdomen;
782 whichjointendarray[18]=leftelbow;
784 whichjointstartarray[19]=abdomen;
785 whichjointendarray[19]=leftwrist;
787 whichjointstartarray[20]=abdomen;
788 whichjointendarray[20]=lefthand;
790 whichjointstartarray[21]=leftshoulder;
791 whichjointendarray[21]=leftelbow;
793 whichjointstartarray[22]=leftelbow;
794 whichjointendarray[22]=leftwrist;
796 whichjointstartarray[23]=leftwrist;
797 whichjointendarray[23]=lefthand;
799 whichjointstartarray[24]=abdomen;
800 whichjointendarray[24]=neck;
802 whichjointstartarray[25]=neck;
803 whichjointendarray[25]=head;
805 FadeLoadingScreen(0);
809 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
811 int temptexdetail=texdetail;
813 text.LoadFontTexture(":Data:Textures:Font.png");
815 texdetail=temptexdetail;
817 FadeLoadingScreen(10);
833 memset(channels, 0xff, sizeof(channels));
835 LOG("Initializing sound system...");
840 extern bool cmdline(const char *cmd);
841 unsigned char rc = 0;
842 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
843 if (cmdline("forceoss")) // ...but let user override that.
844 output = OPENAL_OUTPUT_OSS;
845 else if (cmdline("nosound"))
846 output = OPENAL_OUTPUT_NOSOUND;
848 OPENAL_SetOutput(output);
849 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
851 // if we tried ALSA and failed, fall back to OSS.
852 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
855 output = OPENAL_OUTPUT_OSS;
856 OPENAL_SetOutput(output);
857 rc = OPENAL_Init(44100, 32, 0);
864 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
865 OPENAL_SetOutput(output);
866 rc = OPENAL_Init(44100, 32, 0);
869 OPENAL_Init(44100, 32, 0);
872 OPENAL_SetSFXMasterVolume((int)(volume*255));
876 PlayStreamEx(stream_music3, samp[stream_music3], 0, true);
877 OPENAL_SetPaused(channels[stream_music3], false);
878 OPENAL_SetVolume(channels[stream_music3], 256);
881 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
883 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
884 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
885 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
887 temptexdetail=texdetail;
888 if(texdetail>2)texdetail=2;
889 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
890 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
891 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
892 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
893 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
894 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
895 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
896 texdetail=temptexdetail;
901 FadeLoadingScreen(95);
912 newscreenwidth=screenwidth;
913 newscreenheight=screenheight;
917 void Game::LoadStuff()
919 static float temptexdetail;
920 static float viewdistdetail;
921 static int i,j,texsize;
928 /*musicvolume[3]=512;
929 PlaySoundEx( music4, samp[music4], NULL, true);
930 OPENAL_SetPaused(channels[music4], false);
931 OPENAL_SetVolume(channels[music4], 512);
937 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
939 for(i=0;i<maxplayers;i++)
941 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
943 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
945 player[i].skeleton.drawmodel.textureptr=0;;
948 //temptexdetail=texdetail;
951 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
952 //texdetail=temptexdetail;
954 temptexdetail=texdetail;
956 text.LoadFontTexture(":Data:Textures:Font.png");
958 texdetail=temptexdetail;
963 viewdistance=50*megascale*viewdistdetail;
983 realtexdetail=texdetail;
986 if(texdetail<1)texdetail=1;
987 realtexdetail=texdetail*4;
993 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
995 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
997 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1001 LOG("Loading weapon data...");
1003 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1004 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1005 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1006 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1007 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1008 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1009 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1011 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1012 weapons.throwingknifemodel.Scale(.001,.001,.001);
1013 //weapons.throwingknifemodel.Rotate(0,0,-90);
1014 weapons.throwingknifemodel.Rotate(90,0,0);
1015 weapons.throwingknifemodel.Rotate(0,90,0);
1016 weapons.throwingknifemodel.flat=0;
1017 weapons.throwingknifemodel.CalculateNormals(1);
1018 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1020 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1021 weapons.swordmodel.Scale(.001,.001,.001);
1022 //weapons.swordmodel.Rotate(0,0,-90);
1023 weapons.swordmodel.Rotate(90,0,0);
1024 weapons.swordmodel.Rotate(0,90,0);
1025 weapons.swordmodel.Rotate(0,0,90);
1026 weapons.swordmodel.flat=1;
1027 weapons.swordmodel.CalculateNormals(1);
1028 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1030 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1031 weapons.staffmodel.Scale(.005,.005,.005);
1032 //weapons.staffmodel.Rotate(0,0,-90);
1033 weapons.staffmodel.Rotate(90,0,0);
1034 weapons.staffmodel.Rotate(0,90,0);
1035 weapons.staffmodel.Rotate(0,0,90);
1036 weapons.staffmodel.flat=1;
1037 weapons.staffmodel.CalculateNormals(1);
1038 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1040 //temptexdetail=texdetail;
1041 //if(texdetail>4)texdetail=4;
1042 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1044 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1046 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1048 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1051 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1053 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1055 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1057 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1059 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1061 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1063 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1065 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1066 //texdetail=temptexdetail;
1067 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1071 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1073 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1076 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1079 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1080 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1081 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1082 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1083 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1084 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1085 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1086 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1087 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1088 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1089 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1093 ReSizeGLScene(90,.01);
1100 if(detail)kTextureSize=1024;
1101 if(detail==1)kTextureSize=512;
1102 if(detail==0)kTextureSize=256;
1105 //drawmode=motionblurmode;
1107 //Set up distant light
1111 light.ambient[0]=.2;
1112 light.ambient[1]=.2;
1113 light.ambient[2]=.24;
1116 light.location.z=-.2;
1117 Normalise(&light.location);
1127 texscale=.2/megascale/viewdistdetail;
1128 terrain.scale=3*megascale*terraindetail*viewdistdetail;
1130 viewer.x=terrain.size/2*terrain.scale;
1131 viewer.z=terrain.size/2*terrain.scale;
1133 hawk.load((char *)":Data:Models:hawk.solid",1);
1134 hawk.Scale(.03,.03,.03);
1135 hawk.Rotate(90,1,1);
1136 hawk.CalculateNormals(0);
1137 hawk.ScaleNormals(-1,-1,-1);
1138 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1139 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1140 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1143 eye.load((char *)":Data:Models:eye.solid",1);
1144 eye.Scale(.03,.03,.03);
1145 eye.CalculateNormals(0);
1147 cornea.load((char *)":Data:Models:cornea.solid",1);
1148 cornea.Scale(.03,.03,.03);
1149 cornea.CalculateNormals(0);
1151 iris.load((char *)":Data:Models:iris.solid",1);
1152 iris.Scale(.03,.03,.03);
1153 iris.CalculateNormals(0);
1155 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1156 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1164 //if(targetlevel!=7)
1165 Loadlevel(targetlevel);
1168 rabbitcoords=player[0].coords;
1169 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1171 loadAllAnimations();
1172 //Fix knife stab, too lazy to do it manually
1176 for(i=0;i<player[0].skeleton.num_joints;i++){
1177 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1178 animation[knifesneakattackanim].position[i][j]+=moveamount;
1185 for(i=0;i<player[0].skeleton.num_joints;i++){
1186 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1187 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1194 for(i=0;i<player[0].skeleton.num_joints;i++){
1195 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1196 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1197 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1198 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1200 animation[dead1anim].speed[0]=0.001;
1201 animation[dead2anim].speed[0]=0.001;
1202 animation[dead3anim].speed[0]=0.001;
1203 animation[dead4anim].speed[0]=0.001;
1205 animation[dead1anim].speed[1]=0.001;
1206 animation[dead2anim].speed[1]=0.001;
1207 animation[dead3anim].speed[1]=0.001;
1208 animation[dead4anim].speed[1]=0.001;
1210 for(i=0;i<player[0].skeleton.num_joints;i++){
1211 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1212 animation[swordsneakattackanim].position[i][j]+=moveamount;
1217 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1218 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1224 for(i=0;i<player[0].skeleton.num_joints;i++){
1225 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1226 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1230 for(i=0;i<player[0].skeleton.num_joints;i++){
1231 for(j=0;j<animation[sleepanim].numframes;j++){
1232 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1238 temptexdetail=texdetail;
1240 texdetail=temptexdetail;
1247 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1249 glGenTextures( 1, &screentexture );
1250 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1253 glEnable(GL_TEXTURE_2D);
1254 glBindTexture( GL_TEXTURE_2D, screentexture);
1255 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1256 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1258 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1262 emit_sound_at(fireendsound);