2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "openal_wrapper.h"
24 #include "Animation.h"
26 extern float screenwidth,screenheight;
27 extern float viewdistance;
29 extern XYZ lightlocation;
30 extern float lightambient[3],lightbrightness[3];
31 extern float fadestart;
32 extern float texscale;
35 extern Skeleton testskeleton;
37 extern Terrain terrain;
38 //extern Sprites sprites;
39 extern int kTextureSize;
40 extern float texdetail;
41 extern float realtexdetail;
42 extern float terraindetail;
44 extern Objects objects;
46 extern bool cellophane;
47 extern GLubyte bloodText[512*512*3];
48 extern GLubyte wolfbloodText[512*512*3];
49 extern bool ismotionblur;
50 extern bool trilinear;
52 extern bool musictoggle;
53 extern int environment;
54 extern bool ambientsound;
55 extern float multiplier;
56 extern int netdatanew;
58 extern bool stillloading;
59 extern TGAImageRec texture;
63 extern int oldmainmenu;
64 extern bool visibleloading;
65 extern int loadscreencolor;
66 extern float flashamount,flashr,flashg,flashb;
67 extern int flashdelay;
68 extern int whichjointstartarray[26];
69 extern int whichjointendarray[26];
70 extern int difficulty;
71 extern float tintr,tintg,tintb;
72 extern float slomospeed;
73 extern char mapname[256];
74 extern bool gamestarted;
76 extern int numdialogues;
77 extern int numdialogueboxes[20];
78 extern int dialoguetype[20];
79 extern int dialogueboxlocation[20][20];
80 extern float dialogueboxcolor[20][20][3];
81 extern int dialogueboxsound[20][20];
82 extern char dialoguetext[20][20][128];
83 extern char dialoguename[20][20][64];
84 extern XYZ dialoguecamera[20][20];
85 extern float dialoguecamerarotation[20][20];
86 extern float dialoguecamerarotation2[20][20];
87 extern int indialogue;
88 extern int whichdialogue;
89 extern float dialoguetime;
91 extern float accountcampaignhighscore[10];
92 extern float accountcampaignfasttime[10];
93 extern float accountcampaignscore[10];
94 extern float accountcampaigntime[10];
96 extern int accountcampaignchoicesmade[10];
97 extern int accountcampaignchoices[10][5000];
99 void LOG(const std::string &fmt, ...)
101 // !!! FIXME: write me.
105 Game::TextureList Game::textures;
114 accountactive->endGame();
118 Account::saveFile(":Data:Users", accountactive);
120 TexIter it = textures.begin();
121 for (; it != textures.end(); ++it)
123 if (glIsTexture(it->second))
124 glDeleteTextures(1, &it->second);
128 LOG("Shutting down sound system...");
130 OPENAL_StopSound(OPENAL_ALL);
132 // this is causing problems on Linux, but we'll force an _exit() a little
133 // later in the shutdown process. --ryan.
136 for (i=0; i < sounds_count; ++i)
138 OPENAL_Sample_Free(samp[i]);
151 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
157 LOG(std::string("Loading texture...") + fileName);
159 // Fix filename so that is os appropreate
160 char * fixedFN = ConvertFileName(fileName);
162 unsigned char fileNamep[256];
163 CopyCStringToPascal(fixedFN, fileNamep);
165 upload_image( fileNamep ,hasalpha);
167 // std::string fname(fileName);
168 // std::transform(fname.begin(), fname.end(), tolower);
169 // TexIter it = textures.find(fname);
173 //if(textures.end() == it)
176 if ( texture.bpp == 24 )
181 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
184 glGenTextures( 1, textureid );
185 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
187 glBindTexture( GL_TEXTURE_2D, *textureid);
188 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
189 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
190 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
191 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
193 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
197 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
205 LOG(std::string("Loading texture (S)...") + fileName);
208 unsigned char fileNamep[256];
209 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
211 upload_image( fileNamep ,0);
212 //LoadTGA( fileName );
214 // std::string fname(fileName);
215 // std::transform(fname.begin(), fname.end(), tolower);
216 // TexIter it = textures.find(fname);
220 //if(textures.end() == it)
222 bytesPerPixel=texture.bpp/8;
225 if ( texture.bpp == 24 )
230 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
232 if(!*textureid)glGenTextures( 1, textureid );
233 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
235 glBindTexture( GL_TEXTURE_2D, *textureid);
236 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
237 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
238 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
239 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
242 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
243 if((i+1)%4||type==GL_RGB){
244 array[tempnum]=texture.data[i];
249 *skinsize=texture.sizeX;
251 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
253 // textures.insert(std::make_pair(fname, *textureid));
257 // *textureid = it->second;
261 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
268 LOG(std::string("Loading (S)...") + fileName);
271 float temptexdetail=texdetail;
273 //upload_image( fileName );
274 //LoadTGA( fileName );
276 // Converting file to something os specific
277 char * fixedFN = ConvertFileName(fileName);
280 unsigned char fileNamep[256];
281 CopyCStringToPascal(fixedFN, fileNamep);
283 upload_image( fileNamep ,0);
284 texdetail=temptexdetail;
288 bytesPerPixel=texture.bpp/8;
291 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
292 if((i+1)%4||bytesPerPixel==3){
293 array[tempnum]=texture.data[i];
300 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
307 //upload_image( fileName );
308 //LoadTGA( fileName );
310 unsigned char fileNamep[256];
311 CopyCStringToPascal(fileName,fileNamep);
314 opened=upload_image( fileNamep ,1);
327 bytesPerPixel=texture.bpp/8;
331 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
332 if(bytesPerPixel==3)alphanum=255;
333 else if((i+1)%4==0)alphanum=texture.data[i];
335 if((i+1)%4||bytesPerPixel==3){
336 if((i%4)==0)texture.data[i]*=tintr;
337 if((i%4)==1)texture.data[i]*=tintg;
338 if((i%4)==2)texture.data[i]*=tintb;
339 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
349 //***************> ResizeGLScene() <******/
350 GLvoid Game::ReSizeGLScene(float fov, float pnear)
357 glViewport(0,0,screenwidth,screenheight);
359 glMatrixMode(GL_PROJECTION);
362 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
364 glMatrixMode(GL_MODELVIEW);
368 void Game::LoadingScreen()
370 static float loadprogress,minprogress,maxprogress;
371 static AbsoluteTime time = {0,0};
372 static AbsoluteTime frametime = {0,0};
373 AbsoluteTime currTime = UpTime ();
374 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
376 if (0 > deltaTime) // if negative microseconds
377 deltaTime /= -1000000.0;
378 else // else milliseconds
381 multiplier=deltaTime;
382 if(multiplier<.001)multiplier=.001;
383 if(multiplier>10)multiplier=10;
385 frametime = currTime; // reset for next time interval
390 glClearColor(0,0,0,1);
391 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
394 loadtime+=multiplier*4;
396 loadprogress=loadtime;
397 if(loadprogress>100)loadprogress=100;
399 //loadprogress=abs(Random()%100);
403 glEnable(GL_TEXTURE_2D);
404 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
405 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
406 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
407 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
408 glDisable(GL_CULL_FACE);
409 glDisable(GL_LIGHTING);
411 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
412 glPushMatrix(); // Store The Projection Matrix
413 glLoadIdentity(); // Reset The Projection Matrix
414 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
415 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
416 glPushMatrix(); // Store The Modelview Matrix
417 glLoadIdentity(); // Reset The Modelview Matrix
418 glTranslatef(screenwidth/2,screenheight/2,0);
419 glScalef((float)screenwidth/2,(float)screenheight/2,1);
420 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
422 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
423 //glColor4f(1,1,1,1);
424 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
425 if(loadscreencolor==1)glColor4f(1,0,0,1);
426 if(loadscreencolor==2)glColor4f(0,1,0,1);
427 if(loadscreencolor==3)glColor4f(0,0,1,1);
428 if(loadscreencolor==4)glColor4f(1,1,0,1);
429 if(loadscreencolor==5)glColor4f(1,0,1,1);
432 //glScalef(.25,.25,.25);
434 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
435 glVertex3f(-1, -1, 0.0f);
436 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
437 glVertex3f(1, -1, 0.0f);
438 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
439 glVertex3f(1, 1, 0.0f);
440 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
441 glVertex3f(-1, 1, 0.0f);
446 //glScalef(.25,.25,.25);
448 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
449 glVertex3f(-1, -1, 0.0f);
450 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
451 glVertex3f(1, -1, 0.0f);
452 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
453 glVertex3f(1, 1, 0.0f);
454 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
455 glVertex3f(-1, 1, 0.0f);
458 glDisable(GL_TEXTURE_2D);
459 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
460 glPopMatrix(); // Restore The Old Projection Matrix
461 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
462 glPopMatrix(); // Restore The Old Projection Matrix
466 glEnable(GL_TEXTURE_2D);
467 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
468 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
469 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
470 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
471 glDisable(GL_CULL_FACE);
472 glDisable(GL_LIGHTING);
474 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
475 glPushMatrix(); // Store The Projection Matrix
476 glLoadIdentity(); // Reset The Projection Matrix
477 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
478 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
479 glPushMatrix(); // Store The Modelview Matrix
480 glLoadIdentity(); // Reset The Modelview Matrix
481 glTranslatef(screenwidth/2,screenheight/2,0);
482 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
483 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
485 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
486 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
487 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
488 if(loadscreencolor==1)glColor4f(1,0,0,1);
489 if(loadscreencolor==2)glColor4f(0,1,0,1);
490 if(loadscreencolor==3)glColor4f(0,0,1,1);
491 if(loadscreencolor==4)glColor4f(1,1,0,1);
492 if(loadscreencolor==5)glColor4f(1,0,1,1);
495 //glScalef(.25,.25,.25);
497 glTexCoord2f(0+.5,0+.5);
498 glVertex3f(-1, -1, 0.0f);
499 glTexCoord2f(1+.5,0+.5);
500 glVertex3f(1, -1, 0.0f);
501 glTexCoord2f(1+.5,1+.5);
502 glVertex3f(1, 1, 0.0f);
503 glTexCoord2f(0+.5,1+.5);
504 glVertex3f(-1, 1, 0.0f);
507 glDisable(GL_TEXTURE_2D);
508 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
509 glPopMatrix(); // Restore The Old Projection Matrix
510 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
511 glPopMatrix(); // Restore The Old Projection Matrix
515 glEnable(GL_TEXTURE_2D);
516 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
517 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
518 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
519 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
520 glDisable(GL_CULL_FACE);
521 glDisable(GL_LIGHTING);
523 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
524 glPushMatrix(); // Store The Projection Matrix
525 glLoadIdentity(); // Reset The Projection Matrix
526 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
527 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
528 glPushMatrix(); // Store The Modelview Matrix
529 glLoadIdentity(); // Reset The Modelview Matrix
530 glTranslatef(screenwidth/2,screenheight/2,0);
531 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
532 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
534 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
536 //glScalef(.25,.25,.25);
538 glTexCoord2f(0+.2,0+.8);
539 glVertex3f(-1, -1, 0.0f);
540 glTexCoord2f(1+.2,0+.8);
541 glVertex3f(1, -1, 0.0f);
542 glTexCoord2f(1+.2,1+.8);
543 glVertex3f(1, 1, 0.0f);
544 glTexCoord2f(0+.2,1+.8);
545 glVertex3f(-1, 1, 0.0f);
548 glDisable(GL_TEXTURE_2D);
549 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
550 glPopMatrix(); // Restore The Old Projection Matrix
551 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
552 glPopMatrix(); // Restore The Old Projection Matrix
558 glEnable(GL_TEXTURE_2D);
559 static char string[256]="";
560 sprintf (string, "LOADING... %d%",(int)loadprogress);
562 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
563 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
564 text.glPrint(280,125,string,1,1,640,480);
568 if(flashamount>1)flashamount=1;
569 if(flashdelay<=0)flashamount-=multiplier;
571 if(flashamount<0)flashamount=0;
572 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
573 glDisable(GL_CULL_FACE);
574 glDisable(GL_LIGHTING);
575 glDisable(GL_TEXTURE_2D);
577 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
578 glPushMatrix(); // Store The Projection Matrix
579 glLoadIdentity(); // Reset The Projection Matrix
580 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
581 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
582 glPushMatrix(); // Store The Modelview Matrix
583 glLoadIdentity(); // Reset The Modelview Matrix
584 glScalef(screenwidth,screenheight,1);
585 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
587 glColor4f(flashr,flashg,flashb,flashamount);
589 glVertex3f(0, 0, 0.0f);
590 glVertex3f(256, 0, 0.0f);
591 glVertex3f(256, 256, 0.0f);
592 glVertex3f(0, 256, 0.0f);
594 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
595 glPopMatrix(); // Restore The Old Projection Matrix
596 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
597 glPopMatrix(); // Restore The Old Projection Matrix
598 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
599 glEnable(GL_CULL_FACE);
609 void Game::FadeLoadingScreen(float howmuch)
611 static float loadprogress,minprogress,maxprogress;
616 glClearColor(0,0,0,1);
617 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
619 loadprogress=howmuch;
621 //loadprogress=abs(Random()%100);
625 //glEnable(GL_TEXTURE_2D);
626 glDisable(GL_TEXTURE_2D);
627 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
628 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
629 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
630 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
631 glDisable(GL_CULL_FACE);
632 glDisable(GL_LIGHTING);
634 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
635 glPushMatrix(); // Store The Projection Matrix
636 glLoadIdentity(); // Reset The Projection Matrix
637 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
638 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
639 glPushMatrix(); // Store The Modelview Matrix
640 glLoadIdentity(); // Reset The Modelview Matrix
641 glTranslatef(screenwidth/2,screenheight/2,0);
642 glScalef((float)screenwidth/2,(float)screenheight/2,1);
643 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
645 glColor4f(loadprogress/100,0,0,1);
646 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
647 if(loadscreencolor==1)glColor4f(1,0,0,1);
648 if(loadscreencolor==2)glColor4f(0,1,0,1);
649 if(loadscreencolor==3)glColor4f(0,0,1,1);
650 if(loadscreencolor==4)glColor4f(1,1,0,1);
651 if(loadscreencolor==5)glColor4f(1,0,1,1);
654 //glScalef(.25,.25,.25);
657 glVertex3f(-1, -1, 0.0f);
659 glVertex3f(1, -1, 0.0f);
661 glVertex3f(1, 1, 0.0f);
663 glVertex3f(-1, 1, 0.0f);
666 glDisable(GL_TEXTURE_2D);
667 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
668 glPopMatrix(); // Restore The Old Projection Matrix
669 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
670 glPopMatrix(); // Restore The Old Projection Matrix
675 glEnable(GL_TEXTURE_2D);
676 static char string[256]="";
677 sprintf (string, "LOADING... %d%",(int)loadprogress);
679 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
680 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
681 text.glPrint(280,125,string,1,1,640,480);
688 void Game::InitGame()
691 ProcessSerialNumber PSN;
692 ProcessInfoRec pinfo;
695 /* set up process serial number */
696 PSN.highLongOfPSN = 0;
697 PSN.lowLongOfPSN = kCurrentProcess;
698 /* set up info block */
699 pinfo.processInfoLength = sizeof(pinfo);
700 pinfo.processName = NULL;
701 pinfo.processAppSpec = &pspec;
702 /* grab the vrefnum and directory */
703 err = GetProcessInformation(&PSN, &pinfo);
705 vRefNum = pspec.vRefNum;
716 numchallengelevels=14;
718 accountactive=Account::loadFile(":Data:Users");
724 whichjointstartarray[0]=righthip;
725 whichjointendarray[0]=rightfoot;
727 whichjointstartarray[1]=righthip;
728 whichjointendarray[1]=rightankle;
730 whichjointstartarray[2]=righthip;
731 whichjointendarray[2]=rightknee;
733 whichjointstartarray[3]=rightknee;
734 whichjointendarray[3]=rightankle;
736 whichjointstartarray[4]=rightankle;
737 whichjointendarray[4]=rightfoot;
739 whichjointstartarray[5]=lefthip;
740 whichjointendarray[5]=leftfoot;
742 whichjointstartarray[6]=lefthip;
743 whichjointendarray[6]=leftankle;
745 whichjointstartarray[7]=lefthip;
746 whichjointendarray[7]=leftknee;
748 whichjointstartarray[8]=leftknee;
749 whichjointendarray[8]=leftankle;
751 whichjointstartarray[9]=leftankle;
752 whichjointendarray[9]=leftfoot;
754 whichjointstartarray[10]=abdomen;
755 whichjointendarray[10]=rightshoulder;
757 whichjointstartarray[11]=abdomen;
758 whichjointendarray[11]=rightelbow;
760 whichjointstartarray[12]=abdomen;
761 whichjointendarray[12]=rightwrist;
763 whichjointstartarray[13]=abdomen;
764 whichjointendarray[13]=righthand;
766 whichjointstartarray[14]=rightshoulder;
767 whichjointendarray[14]=rightelbow;
769 whichjointstartarray[15]=rightelbow;
770 whichjointendarray[15]=rightwrist;
772 whichjointstartarray[16]=rightwrist;
773 whichjointendarray[16]=righthand;
775 whichjointstartarray[17]=abdomen;
776 whichjointendarray[17]=leftshoulder;
778 whichjointstartarray[18]=abdomen;
779 whichjointendarray[18]=leftelbow;
781 whichjointstartarray[19]=abdomen;
782 whichjointendarray[19]=leftwrist;
784 whichjointstartarray[20]=abdomen;
785 whichjointendarray[20]=lefthand;
787 whichjointstartarray[21]=leftshoulder;
788 whichjointendarray[21]=leftelbow;
790 whichjointstartarray[22]=leftelbow;
791 whichjointendarray[22]=leftwrist;
793 whichjointstartarray[23]=leftwrist;
794 whichjointendarray[23]=lefthand;
796 whichjointstartarray[24]=abdomen;
797 whichjointendarray[24]=neck;
799 whichjointstartarray[25]=neck;
800 whichjointendarray[25]=head;
802 FadeLoadingScreen(0);
806 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
808 int temptexdetail=texdetail;
810 text.LoadFontTexture(":Data:Textures:Font.png");
812 texdetail=temptexdetail;
814 FadeLoadingScreen(10);
830 LOG("Initializing sound system...");
835 extern bool cmdline(const char *cmd);
836 unsigned char rc = 0;
837 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
838 if (cmdline("forceoss")) // ...but let user override that.
839 output = OPENAL_OUTPUT_OSS;
840 else if (cmdline("nosound"))
841 output = OPENAL_OUTPUT_NOSOUND;
843 OPENAL_SetOutput(output);
844 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
846 // if we tried ALSA and failed, fall back to OSS.
847 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
850 output = OPENAL_OUTPUT_OSS;
851 OPENAL_SetOutput(output);
852 rc = OPENAL_Init(44100, 32, 0);
859 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
860 OPENAL_SetOutput(output);
861 rc = OPENAL_Init(44100, 32, 0);
864 OPENAL_Init(44100, 32, 0);
867 OPENAL_SetSFXMasterVolume((int)(volume*255));
871 emit_stream_np(stream_music3);
873 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
875 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
876 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
877 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
879 temptexdetail=texdetail;
880 if(texdetail>2)texdetail=2;
881 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
882 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
883 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
884 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
885 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
886 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
887 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
888 texdetail=temptexdetail;
893 FadeLoadingScreen(95);
904 newscreenwidth=screenwidth;
905 newscreenheight=screenheight;
909 void Game::LoadStuff()
911 static float temptexdetail;
912 static float viewdistdetail;
913 static int i,j,texsize;
924 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
926 for(i=0;i<maxplayers;i++)
928 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
930 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
932 player[i].skeleton.drawmodel.textureptr=0;;
935 //temptexdetail=texdetail;
938 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
939 //texdetail=temptexdetail;
941 temptexdetail=texdetail;
943 text.LoadFontTexture(":Data:Textures:Font.png");
945 texdetail=temptexdetail;
950 viewdistance=50*megascale*viewdistdetail;
970 realtexdetail=texdetail;
973 if(texdetail<1)texdetail=1;
974 realtexdetail=texdetail*4;
980 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
982 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
984 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
988 LOG("Loading weapon data...");
990 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
991 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
992 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
993 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
994 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
995 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
996 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
998 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
999 weapons.throwingknifemodel.Scale(.001,.001,.001);
1000 //weapons.throwingknifemodel.Rotate(0,0,-90);
1001 weapons.throwingknifemodel.Rotate(90,0,0);
1002 weapons.throwingknifemodel.Rotate(0,90,0);
1003 weapons.throwingknifemodel.flat=0;
1004 weapons.throwingknifemodel.CalculateNormals(1);
1005 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1007 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1008 weapons.swordmodel.Scale(.001,.001,.001);
1009 //weapons.swordmodel.Rotate(0,0,-90);
1010 weapons.swordmodel.Rotate(90,0,0);
1011 weapons.swordmodel.Rotate(0,90,0);
1012 weapons.swordmodel.Rotate(0,0,90);
1013 weapons.swordmodel.flat=1;
1014 weapons.swordmodel.CalculateNormals(1);
1015 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1017 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1018 weapons.staffmodel.Scale(.005,.005,.005);
1019 //weapons.staffmodel.Rotate(0,0,-90);
1020 weapons.staffmodel.Rotate(90,0,0);
1021 weapons.staffmodel.Rotate(0,90,0);
1022 weapons.staffmodel.Rotate(0,0,90);
1023 weapons.staffmodel.flat=1;
1024 weapons.staffmodel.CalculateNormals(1);
1025 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1027 //temptexdetail=texdetail;
1028 //if(texdetail>4)texdetail=4;
1029 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1031 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1033 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1035 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1038 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1040 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1042 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1044 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1046 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1048 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1050 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1052 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1053 //texdetail=temptexdetail;
1054 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1058 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1060 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1063 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1066 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1067 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1068 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1069 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1070 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1071 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1072 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1073 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1074 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1075 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1076 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1080 ReSizeGLScene(90,.01);
1087 if(detail)kTextureSize=1024;
1088 if(detail==1)kTextureSize=512;
1089 if(detail==0)kTextureSize=256;
1092 //drawmode=motionblurmode;
1094 //Set up distant light
1098 light.ambient[0]=.2;
1099 light.ambient[1]=.2;
1100 light.ambient[2]=.24;
1103 light.location.z=-.2;
1104 Normalise(&light.location);
1114 texscale=.2/megascale/viewdistdetail;
1115 terrain.scale=3*megascale*terraindetail*viewdistdetail;
1117 viewer.x=terrain.size/2*terrain.scale;
1118 viewer.z=terrain.size/2*terrain.scale;
1120 hawk.load((char *)":Data:Models:hawk.solid",1);
1121 hawk.Scale(.03,.03,.03);
1122 hawk.Rotate(90,1,1);
1123 hawk.CalculateNormals(0);
1124 hawk.ScaleNormals(-1,-1,-1);
1125 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1126 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1127 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1130 eye.load((char *)":Data:Models:eye.solid",1);
1131 eye.Scale(.03,.03,.03);
1132 eye.CalculateNormals(0);
1134 cornea.load((char *)":Data:Models:cornea.solid",1);
1135 cornea.Scale(.03,.03,.03);
1136 cornea.CalculateNormals(0);
1138 iris.load((char *)":Data:Models:iris.solid",1);
1139 iris.Scale(.03,.03,.03);
1140 iris.CalculateNormals(0);
1142 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1143 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1151 //if(targetlevel!=7)
1152 Loadlevel(targetlevel);
1155 rabbitcoords=player[0].coords;
1156 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1158 loadAllAnimations();
1159 //Fix knife stab, too lazy to do it manually
1163 for(i=0;i<player[0].skeleton.num_joints;i++){
1164 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1165 animation[knifesneakattackanim].position[i][j]+=moveamount;
1172 for(i=0;i<player[0].skeleton.num_joints;i++){
1173 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1174 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1181 for(i=0;i<player[0].skeleton.num_joints;i++){
1182 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1183 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1184 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1185 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1187 animation[dead1anim].speed[0]=0.001;
1188 animation[dead2anim].speed[0]=0.001;
1189 animation[dead3anim].speed[0]=0.001;
1190 animation[dead4anim].speed[0]=0.001;
1192 animation[dead1anim].speed[1]=0.001;
1193 animation[dead2anim].speed[1]=0.001;
1194 animation[dead3anim].speed[1]=0.001;
1195 animation[dead4anim].speed[1]=0.001;
1197 for(i=0;i<player[0].skeleton.num_joints;i++){
1198 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1199 animation[swordsneakattackanim].position[i][j]+=moveamount;
1204 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1205 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1211 for(i=0;i<player[0].skeleton.num_joints;i++){
1212 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1213 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1217 for(i=0;i<player[0].skeleton.num_joints;i++){
1218 for(j=0;j<animation[sleepanim].numframes;j++){
1219 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1225 temptexdetail=texdetail;
1227 texdetail=temptexdetail;
1234 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1236 glGenTextures( 1, &screentexture );
1237 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1240 glEnable(GL_TEXTURE_2D);
1241 glBindTexture( GL_TEXTURE_2D, screentexture);
1242 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1243 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1245 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1249 emit_sound_at(fireendsound);