// Path: src/com/lvonasek/o4s/media/Settings.java
// public class Settings {
// 
//     public static final int          MUSIC_VOLUME   = 0;
//     public static final int          SOUND_VOLUME   = 1;
//     public static final int          VISUAL_QUALITY = 2;
//     public static final int          RACE_EVENT     = 3;
// 
//     public static final String       RACE_CUSTOM_EVENT = "O4SCFG";
// 
//     private static int[]             DEFAULT_VALUES = {100, 100, 100, 0};
// 
//     public static void init(Activity instance) {
//         Display display = instance.getWindowManager().getDefaultDisplay();
//         Point size = new Point();
//         display.getSize(size);
//         int level = 25 + (int) ((Math.max(size.x, size.y) - 800) / 6.4f);
//         level = Math.max(0, Math.min(level, 100));
//         DEFAULT_VALUES[VISUAL_QUALITY] = level;
//         Log.v("Open4speed", "Default visual quality=" + level);
//     }
// 
//     public static int getConfig(Context c, int index) {
//         SharedPreferences pref = c.getSharedPreferences("MyPref", Context.MODE_PRIVATE);
//         return pref.getInt("IntCFG" + index, DEFAULT_VALUES[index]);
//     }
// 
//     public static void setConfig(Context c, int index, int value) {
//         SharedPreferences pref = c.getSharedPreferences("MyPref", Context.MODE_PRIVATE);
//         SharedPreferences.Editor edit = pref.edit();
//         edit.putInt("IntCFG" + index, value);
//         edit.commit();
//     }
// 
//     public static String getConfig(Context c, String str) {
//         SharedPreferences pref = c.getSharedPreferences("MyPref", Context.MODE_PRIVATE);
//         return pref.getString(str, "");
//     }
// 
//     public static void setConfig(Context c, String str, String value) {
//         SharedPreferences pref = c.getSharedPreferences("MyPref", Context.MODE_PRIVATE);
//         SharedPreferences.Editor edit = pref.edit();
//         edit.putString(str, value);
//         edit.commit();
//     }
// }
// 
// Path: src/com/lvonasek/o4s/media/Sound.java
// public class Sound {
// 
//     public static SoundPool snd = new SoundPool(16, AudioManager.STREAM_MUSIC, 0);
// 
//     public static float globalVolume = 1;
// 
//     int id;
//     boolean loop;
//     boolean playing;
//     float rate;
//     float volume;
// 
//     public Sound(String filename, boolean loop) {
//         //unzip file(Android java access)
//         try {
//             AssetFileDescriptor afd = GameActivity.instance.getAssets().openFd(filename);
//             id = snd.load(afd, 1);
//         } catch (IOException e) {
//             e.printStackTrace();
//             this.id = -1;
//         }
//         this.loop = loop;
//         this.rate = 1;
//         this.volume = 0;
//         playing = false;
//     }
// 
//     public void play() {
//         if (GameLoop.paused == 0) {
//             //play sound
//             if (playing)
//                 snd.pause(id);
//             snd.play(id, volume, volume, 1, loop ? -1 : 1, rate);
//             playing = true;
//         }
//     }
// 
//     /**
//      * Change frequency of sound(engine, n2o)
//      * @param speed is play rate(from 0.5 to 2.0)
//      */
//     public void setFreq(float speed) {
//         //clamp rate speed
//         rate = speed;
//         if (speed < 0.5) {
//             rate = 0.5f;
//         }
//         if (speed > 2.0) {
//             rate = 2.0f;
//         }
//     }
// 
//     /**
//      * Set sound volume
//      * @param volume is sound volume(from 0 to 1)
//      */
//     public void setVolume(float volume) {
//         //audio clip
//         if (GameLoop.paused == 0) {
//             volume *= 0.25f;
//             this.volume = volume * globalVolume;
//         }
//     }
// 
//     /**
//      * Stops playing sound
//      */
//     public void stop() {
//         //audio clip
//         if ((GameLoop.paused == 0) && playing) {
//             snd.stop(id);
//             playing = false;
//         }
//     }
// }


import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.util.AttributeSet;
import android.view.View;
import com.lvonasek.o4s.R;
import com.lvonasek.o4s.media.Settings;
import com.lvonasek.o4s.media.Sound;
import java.util.ArrayList;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
package com.lvonasek.o4s.game;





/**
 * Communication with native C++ code from java. It is also managing threads for graphical
 * and non-graphical processes. Main function of this class is calling C++ methods.
 * @author Lubos Vonasek
 */
public class GameLoop extends GLSurfaceView implements Renderer {

    public static final int CAR_INFO_SPEED = 0;
    public static final int CAR_INFO_PEDAL_GAS = 1;
    public static final int CAR_INFO_PEDAL_BRAKE = 2;
    public static final int CAR_INFO_REVERSE = 3;
    public static final int CAR_INFO_LASTSPEED = 4;
    public static final int CAR_INFO_GEARLOW = 5;
    public static final int CAR_INFO_GEARHIGH = 6;
    public static final int CAR_INFO_PEDAL_N2O = 7;
    public static final int CAR_INFO_GEARMIN = 8;
    public static final int CAR_INFO_GEARMAX = 9;
    public static final int CAR_INFO_N2OAMOUNT = 10;
    public static final int CAR_INFO_CAMERADST = 11;
    public static final int CAR_INFO_SNDCRASH = 12;
    public static final int CAR_INFO_SNDDIST = 13;
    public static final int CAR_INFO_SNDENGINE1 = 14;
    public static final int CAR_INFO_SNDENGINE2 = 15;
    public static final int CAR_INFO_SNDN2O = 16;
    public static final int CAR_INFO_SNDRATE = 17;
    public static final int CAR_INFO_TOFINISH = 18;

    //Game state
    public int            currentPlace = 0;
    public static int     paused       = 0;
    // instance of sounds
// Path: src/com/lvonasek/o4s/media/Settings.java
// public class Settings {
// 
//     public static final int          MUSIC_VOLUME   = 0;
//     public static final int          SOUND_VOLUME   = 1;
//     public static final int          VISUAL_QUALITY = 2;
//     public static final int          RACE_EVENT     = 3;
// 
//     public static final String       RACE_CUSTOM_EVENT = "O4SCFG";
// 
//     private static int[]             DEFAULT_VALUES = {100, 100, 100, 0};
// 
//     public static void init(Activity instance) {
//         Display display = instance.getWindowManager().getDefaultDisplay();
//         Point size = new Point();
//         display.getSize(size);
//         int level = 25 + (int) ((Math.max(size.x, size.y) - 800) / 6.4f);
//         level = Math.max(0, Math.min(level, 100));
//         DEFAULT_VALUES[VISUAL_QUALITY] = level;
//         Log.v("Open4speed", "Default visual quality=" + level);
//     }
// 
//     public static int getConfig(Context c, int index) {
//         SharedPreferences pref = c.getSharedPreferences("MyPref", Context.MODE_PRIVATE);
//         return pref.getInt("IntCFG" + index, DEFAULT_VALUES[index]);
//     }
// 
//     public static void setConfig(Context c, int index, int value) {
//         SharedPreferences pref = c.getSharedPreferences("MyPref", Context.MODE_PRIVATE);
//         SharedPreferences.Editor edit = pref.edit();
//         edit.putInt("IntCFG" + index, value);
//         edit.commit();
//     }
// 
//     public static String getConfig(Context c, String str) {
//         SharedPreferences pref = c.getSharedPreferences("MyPref", Context.MODE_PRIVATE);
//         return pref.getString(str, "");
//     }
// 
//     public static void setConfig(Context c, String str, String value) {
//         SharedPreferences pref = c.getSharedPreferences("MyPref", Context.MODE_PRIVATE);
//         SharedPreferences.Editor edit = pref.edit();
//         edit.putString(str, value);
//         edit.commit();
//     }
// }
// 
// Path: src/com/lvonasek/o4s/media/Sound.java
// public class Sound {
// 
//     public static SoundPool snd = new SoundPool(16, AudioManager.STREAM_MUSIC, 0);
// 
//     public static float globalVolume = 1;
// 
//     int id;
//     boolean loop;
//     boolean playing;
//     float rate;
//     float volume;
// 
//     public Sound(String filename, boolean loop) {
//         //unzip file(Android java access)
//         try {
//             AssetFileDescriptor afd = GameActivity.instance.getAssets().openFd(filename);
//             id = snd.load(afd, 1);
//         } catch (IOException e) {
//             e.printStackTrace();
//             this.id = -1;
//         }
//         this.loop = loop;
//         this.rate = 1;
//         this.volume = 0;
//         playing = false;
//     }
// 
//     public void play() {
//         if (GameLoop.paused == 0) {
//             //play sound
//             if (playing)
//                 snd.pause(id);
//             snd.play(id, volume, volume, 1, loop ? -1 : 1, rate);
//             playing = true;
//         }
//     }
// 
//     /**
//      * Change frequency of sound(engine, n2o)
//      * @param speed is play rate(from 0.5 to 2.0)
//      */
//     public void setFreq(float speed) {
//         //clamp rate speed
//         rate = speed;
//         if (speed < 0.5) {
//             rate = 0.5f;
//         }
//         if (speed > 2.0) {
//             rate = 2.0f;
//         }
//     }
// 
//     /**
//      * Set sound volume
//      * @param volume is sound volume(from 0 to 1)
//      */
//     public void setVolume(float volume) {
//         //audio clip
//         if (GameLoop.paused == 0) {
//             volume *= 0.25f;
//             this.volume = volume * globalVolume;
//         }
//     }
// 
//     /**
//      * Stops playing sound
//      */
//     public void stop() {
//         //audio clip
//         if ((GameLoop.paused == 0) && playing) {
//             snd.stop(id);
//             playing = false;
//         }
//     }
// }


// Path: src/com/lvonasek/o4s/game/GameLoop.java
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.util.AttributeSet;
import android.view.View;
import com.lvonasek.o4s.R;
import com.lvonasek.o4s.media.Settings;
import com.lvonasek.o4s.media.Sound;
import java.util.ArrayList;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

package com.lvonasek.o4s.game;





/**
 * Communication with native C++ code from java. It is also managing threads for graphical
 * and non-graphical processes. Main function of this class is calling C++ methods.
 * @author Lubos Vonasek
 */
public class GameLoop extends GLSurfaceView implements Renderer {

    public static final int CAR_INFO_SPEED = 0;
    public static final int CAR_INFO_PEDAL_GAS = 1;
    public static final int CAR_INFO_PEDAL_BRAKE = 2;
    public static final int CAR_INFO_REVERSE = 3;
    public static final int CAR_INFO_LASTSPEED = 4;
    public static final int CAR_INFO_GEARLOW = 5;
    public static final int CAR_INFO_GEARHIGH = 6;
    public static final int CAR_INFO_PEDAL_N2O = 7;
    public static final int CAR_INFO_GEARMIN = 8;
    public static final int CAR_INFO_GEARMAX = 9;
    public static final int CAR_INFO_N2OAMOUNT = 10;
    public static final int CAR_INFO_CAMERADST = 11;
    public static final int CAR_INFO_SNDCRASH = 12;
    public static final int CAR_INFO_SNDDIST = 13;
    public static final int CAR_INFO_SNDENGINE1 = 14;
    public static final int CAR_INFO_SNDENGINE2 = 15;
    public static final int CAR_INFO_SNDN2O = 16;
    public static final int CAR_INFO_SNDRATE = 17;
    public static final int CAR_INFO_TOFINISH = 18;

    //Game state
    public int            currentPlace = 0;
    public static int     paused       = 0;
    // instance of sounds
    private static ArrayList<Sound> sounds;