void Sound_initTracks(void) { const char *music_path; List *soundList; List *p; int i; music_path = getDirectory( PATH_MUSIC ); soundList = readDirectoryContents(music_path, NULL); if(soundList->next == NULL) { fprintf(stderr, "[sound] no music files found...exiting\n"); exit(1); // FIXME: handle missing songs somewhere else } //soundList->data="revenge_of_cats.it"; i = 1; for(p = soundList; p->next != NULL; p = p->next) { // bugfix: filter track list to readable files (and without directories) char *path = getPossiblePath( PATH_MUSIC, (char*)p->data ); if( path != NULL && fileExists( path ) ) { scripting_RunFormat("tracks[%d] = \"%s\"", i, (char*) p->data); i++; free( path ); } } scripting_Run("setupSoundTrack()"); }
void Sound_initTracks(void) { const char *music_path; nebu_List *soundList; nebu_List *p; int i; music_path = getDirectory( PATH_MUSIC ); soundList = readDirectoryContents(music_path, NULL); if(soundList->next == NULL) { fprintf(stderr, "[sound] no music files found...exiting\n"); nebu_assert(0); exit(1); // TODO: handle missing songs somewhere else } i = 1; for(p = soundList; p->next != NULL; p = p->next) { // bugfix: filter track list to readable files (and without directories) char *path = getPossiblePath( PATH_MUSIC, (char*)p->data ); if( path != NULL && nebu_FS_Test( path ) ) { scripting_RunFormat("tracks[%d] = \"%s\"", i, (char*) p->data); i++; free( path ); } free(p->data); } nebu_List_Free(soundList); scripting_Run("setupSoundTrack()"); }
int scripting_RunFormat(const char *format, ... ) { char buf[4096]; va_list ap; va_start(ap, format); vsprintf(buf, format, ap); va_end(ap); return scripting_Run(buf); }
void drawHUD(Player *p, PlayerVisual *pV) { char temp[1024]; char pause_message[128]; float pause_color[3]; getPauseString(pause_message, pause_color); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); rasonly(&pV->display); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* drawHud: parameters - Viewport Width - Viewport Height - Score (or -1 if disabled) - AI status ("computer player" or "") - Speed digital (absolute value) - Speed analog (1 for default speed, > 1 during acceleration) - Booster value (between 0 and 1) - fps - pause message - pause message r,g,b colors */ sprintf(temp, "drawHUD(%d, %d, %d, \"%s\", %f, %f, %f, %f, %d, \"%s\", %f, %f, %f)", pV->display.vp_w, pV->display.vp_h, gSettingsCache.show_scores ? p->data->score : -1, gSettingsCache.show_ai_status ? (p->ai->active ? "AI_COMPUTER" : "") : "", p->data->speed, p->data->speed / (2 * game2->rules.speed), p->data->booster / getSettingf("booster_max"), p->data->wall_buster / getSettingf("wall_buster_max"), getFPS(), pause_message, pause_color[0], pause_color[1], pause_color[2] ); glScalef(pV->display.vp_w / 1024.0f, pV->display.vp_w / 1024.0f, 1.0f); // fprintf(stderr, "%s\n", temp); scripting_Run(temp); glDisable(GL_BLEND); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); }
void saveSettings(void) { char *script; script = getPath(PATH_SCRIPTS, "save.lua"); scripting_RunFile(script); free(script); #ifdef WIN32 scripting_Run("file = io.open(\"gltron.ini\", \"w\")"); scripting_Run("io.output(file)"); #else { char *path = getPossiblePath(PATH_PREFERENCES, RC_NAME); if(path == NULL) return; scripting_RunFormat("file = io.open(\"%s\", \"w\")", path); scripting_Run("io.output(file)"); free(path); } #endif scripting_Run("save()"); scripting_Run("io.write \"save_completed = 1\\n\""); scripting_Run("io.output(io.stdout)"); // select stdout again }
void drawMenu(Visual *d) { /* draw Menu pCurrent */ int i; int x, y, size, lineheight; int hsize, vsize; int max_label = 0; int max_data = 0; int nEntries; char pMenuName[200]; int iActiveItem; rasonly(d); #define MENU_TEXT_START_X 0.08 #define MENU_TEXT_START_Y 0.40 #define MENU_WIDTH 0.80 #define MENU_HEIGHT 0.40 #define MENU_TEXT_LINEHEIGHT 1.5 x = (int) (d->vp_w * MENU_TEXT_START_X); y = (int) (d->vp_h * MENU_TEXT_START_Y); /* obtain menu name */ scripting_Run("return Menu.current"); scripting_CopyStringResult(pMenuName, 200); /* obtain some information about the active menu */ scripting_RunFormat("return table.getn( Menu.%s.items )", pMenuName); scripting_GetIntegerResult(&nEntries); /* new stuff: calculate menu dimensions */ for(i = 0; i < nEntries; i++) { int len_label = 0; int len_data = 0; scripting_RunFormat("return string.len( Menu[Menu.%s.items[%d]].caption )", pMenuName, i + 1); scripting_GetIntegerResult(&len_label); len_label += 2; /* add ': ' */ scripting_RunFormat("return GetMenuValueWidth( Menu.%s.items[%d] )", pMenuName, i + 1); scripting_GetIntegerResult(&len_data); if(len_label > max_label) max_label = len_label; if(len_data > max_data) max_data = len_data; } /* adjust size so menu fits into MENU_WIDTH/HEIGHT */ hsize = (int) ((float)d->vp_w * MENU_WIDTH / (float) (max_label + max_data)); vsize = (int) ((float)d->vp_h * MENU_HEIGHT / ( (float)nEntries * MENU_TEXT_LINEHEIGHT)); size = (hsize < vsize) ? hsize : vsize; lineheight = (int)( (float) size * MENU_TEXT_LINEHEIGHT); /* printf("%d %d %d %d %d\n", x, y, size, maxw, pCurrent->nEntries); */ /* draw the entries */ scripting_Run("return Menu.active"); scripting_GetIntegerResult(&iActiveItem); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); for(i = 0; i < nEntries; i++) { if(i == iActiveItem - 1) { float color[4]; float active1[4]; float active2[4]; int j; float t; int time = nebu_Time_GetElapsed() & 4095; t = sinf( time * PI / 2048.0 ) / 2.0f + 0.5f; scripting_GetGlobal("menu_item_active1", NULL); scripting_GetFloatArrayResult(active1, 4); scripting_GetGlobal("menu_item_active2", NULL); scripting_GetFloatArrayResult(active2, 4); for(j = 0; j < 4; j++) { color[j] = t * active1[j] + (1 - t) * active2[j]; } glColor4fv(color); /* fprintf(stderr, "%.2f: %.2f %.2f %.2f\n", t, color[0], color[1], color[2]); */ } else { float color[4]; scripting_GetGlobal("menu_item", NULL); scripting_GetFloatArrayResult(color, 4); glColor4fv(color); } { char line_label[100]; char line_data[100]; scripting_RunFormat("return " "GetMenuValueString( Menu.%s.items[%d] )", pMenuName, i + 1); scripting_CopyStringResult(line_data, sizeof(line_data)); if(line_data[0] != 0) scripting_RunFormat("return " "Menu[Menu.%s.items[%d]].caption .. ': '", pMenuName, i + 1); else scripting_RunFormat("return " "Menu[Menu.%s.items[%d]].caption", pMenuName, i + 1); scripting_CopyStringResult(line_label, sizeof(line_label)); drawText(guiFtx, (float)x, (float)y, (float)size, line_label); drawText(guiFtx, (float)x + max_label * size, (float)y, (float)size, line_data); } /* if(i == pCurrent->iHighlight) drawSoftwareHighlight(x, y, size, ((Menu*)*(pCurrent->pEntries + i))->display.szCaption); */ y -= lineheight; } glDisable(GL_BLEND); }
void Audio_Idle(void) { // iterate over all the players and update the engines if(sample_engine->IsPlaying()) { for(int i = 0; i < PLAYERS; i++) { Player *p; Sound::Source3D *p3d; float x, y; p3d = players[i]; p = game->player + i; getPositionFromIndex(&x, &y, i); p3d->_location = Vector3(x, y, 0); float V = p->data->speed; int dt = game2->time.current - p->data->turn_time; if(dt < TURN_LENGTH) { float t = (float)dt / TURNLENGTH; float vx = (1 - t) * dirsX[p->data->last_dir] + t * dirsX[p->data->dir]; float vy = (1 - t) * dirsY[p->data->last_dir] + t * dirsY[p->data->dir]; p3d->_velocity = Vector3(V * vx, V * vy, 0); } else { p3d->_velocity = Vector3(V * dirsX[p->data->dir], V * dirsY[p->data->dir], 0); } if(i == 0) { if(p->data->boost_enabled) { ( (Sound::SourceEngine*) p3d )->_speedShift = 1.2f; } else { ( (Sound::SourceEngine*) p3d )->_speedShift = 1.0f; } ( (Sound::SourceEngine*) p3d )->_pitchShift = p->data->speed / getSettingf("speed"); } #if 0 if(i == 0) { if( dt < TURNLENGTH ) { float t = (float)dt / TURNLENGTH; float speedShift = ( 1 - t ) * 0.4 + t * 0.3; float pitchShift = ( 1 - t ) * 0.9 + t * 1.0; ( (Sound::SourceEngine*) p3d )->_speedShift = speedShift; ( (Sound::SourceEngine*) p3d )->_pitchShift = pitchShift; } else { ( (Sound::SourceEngine*) p3d )->_speedShift = 0.3; ( (Sound::SourceEngine*) p3d )->_pitchShift = 1.0; } } #endif } } if(sample_recognizer->IsPlaying()) { if (gSettingsCache.show_recognizer) { vec2 p, v; getRecognizerPositionVelocity(&p, &v); // recognizerEngine->_location = Vector3(p.x, p.y, RECOGNIZER_HEIGHT); recognizerEngine->_location = Vector3(p.v[0], p.v[1], 10.0f); recognizerEngine->_velocity = Vector3(v.v[0], v.v[1], 0); } } if(music && !music->IsPlaying()) { // check if music is enabled. if it is, advance to // next song if(gSettingsCache.playMusic) { scripting_Run("nextTrack()"); } } Sound::Listener& listener = sound->GetListener(); listener._location = Vector3(game->player[0].camera->cam); Vector3 v1 = Vector3(game->player[0].camera->target); Vector3 v2 = Vector3(game->player[0].camera->cam); listener._direction = v1 - v2; // listener._location = players[0]->_location; // listener._direction = players[0]->_velocity; listener._velocity = players[0]->_velocity; listener._up = Vector3(0, 0, 1); sound->SetMixMusic(gSettingsCache.playMusic); sound->SetMixFX(gSettingsCache.playEffects); sound->Idle(); }
void keyboardGui(int state, int key, int x, int y) { char *pMenuName; if(state == SYSTEM_KEYSTATE_UP) return; scripting_Run("return Menu.current"); scripting_GetStringResult(&pMenuName); switch(key) { case 27: if(strcmp(pMenuName, "RootMenu")) { // not in the root menu -> go up one menu scripting_Run("Menu.GotoParent()"); } else { // is a game already in process? then resume if(game->pauseflag != PAUSE_NO_GAME) SystemExitLoop(RETURN_GUI_ESCAPE); } break; case ' ': case SYSTEM_KEY_RETURN: case SYSTEM_JOY_BUTTON_0: case SYSTEM_JOY_BUTTON_1: case SYSTEM_JOY_BUTTON_2: case SYSTEM_JOY_BUTTON_3: case SYSTEM_JOY_BUTTON_4: case SYSTEM_JOY_BUTTON_5: case SYSTEM_JOY_BUTTON_6: case SYSTEM_JOY_BUTTON_7: case SYSTEM_JOY_BUTTON_8: case SYSTEM_JOY_BUTTON_9: case SYSTEM_JOY_BUTTON_0 + SYSTEM_JOY_OFFSET: case SYSTEM_JOY_BUTTON_1 + SYSTEM_JOY_OFFSET: case SYSTEM_JOY_BUTTON_2 + SYSTEM_JOY_OFFSET: case SYSTEM_JOY_BUTTON_3 + SYSTEM_JOY_OFFSET: case SYSTEM_JOY_BUTTON_4 + SYSTEM_JOY_OFFSET: case SYSTEM_JOY_BUTTON_5 + SYSTEM_JOY_OFFSET: case SYSTEM_JOY_BUTTON_6 + SYSTEM_JOY_OFFSET: case SYSTEM_JOY_BUTTON_7 + SYSTEM_JOY_OFFSET: case SYSTEM_JOY_BUTTON_8 + SYSTEM_JOY_OFFSET: case SYSTEM_JOY_BUTTON_9 + SYSTEM_JOY_OFFSET: scripting_Run("Menu.Action()"); break; case SYSTEM_KEY_UP: case SYSTEM_JOY_UP: case SYSTEM_JOY_UP + SYSTEM_JOY_OFFSET: scripting_Run("Menu.Previous()"); break; case SYSTEM_KEY_DOWN: case SYSTEM_JOY_DOWN: case SYSTEM_JOY_DOWN + SYSTEM_JOY_OFFSET: scripting_Run("Menu.Next()"); break; case SYSTEM_KEY_RIGHT: case SYSTEM_JOY_RIGHT: case SYSTEM_JOY_RIGHT + SYSTEM_JOY_OFFSET: scripting_Run("Menu.Right()"); break; case SYSTEM_KEY_LEFT: case SYSTEM_JOY_LEFT: case SYSTEM_JOY_LEFT + SYSTEM_JOY_OFFSET: scripting_Run("Menu.Left()"); break; case SYSTEM_KEY_F11: doBmpScreenShot(gScreen); break; case SYSTEM_KEY_F12: doPngScreenShot(gScreen); break; default: // printf("got key %d\n", key); break; } free(pMenuName); }