Ejemplo n.º 1
0
void model_destroy(model *m)
{
  if (m->capacity > 0) {
    if (m->mu != NULL) free(m->mu);
  }
  model_init(m);
}
Ejemplo n.º 2
0
Archivo: init.c Proyecto: wcasper/fluid
int init() {
  int status = 0;

  // initialize MPI task numbers
  status = comm_init();
  error_check(&status, "error in comm_init\n");
  if(status) return status;

  // initialize grid
  status = grid_init();
  error_check(&status, "error in grid_init\n");
  if(status) return status;

  // initialize fourier
  status = fourier_init();
  error_check(&status, "error in fourier_init\n");
  if(status) return status;

  // initialize state
  status = state_init();
  error_check(&status, "error in state_init\n");
  if(status) return status;

  // initialize model
  status = model_init();
  error_check(&status, "error in model_init\n");
  if(status) return status;

  // initialize time step
  status = time_init();
  error_check(&status, "error in time_init\n");
  if(status) return status;

  return status;
}
Ejemplo n.º 3
0
void
fit_init(fitinfo *fit)
{
  beam_init(&fit->beam);
  pars_init(&fit->pars);
  profile_init(&fit->p);
  model_init(&fit->m);
  interface_init(&fit->rm);
  fit->m.rm = &fit->rm;
  fit->capacity = -1;
  fit->nQ = 0;
  data_init(&fit->dataA);
  data_init(&fit->dataB);
  data_init(&fit->dataC);
  data_init(&fit->dataD);
  fit->worksize = 0;
  fit->datatype = FIT_MAGNITUDE;
  fit->weight = 1.;
  fit->penalty = 0.;

  /* Parameters to support incoherent sum of models */
  fit->number_incoherent = 0;
  fit->incoherent_models = NULL;
  fit->incoherent_weights = NULL;
}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: Tayyib/uludag
int
main(int argc, char *argv[])
{
    // l10n
    setlocale(LC_MESSAGES, "");
    bindtextdomain("comar", "/usr/share/locale");
    bind_textdomain_codeset("comar", "UTF-8");
    bind_textdomain_codeset("libc", "UTF-8");
    textdomain("comar");

    // Parse commandline options
    cfg_init(argc, argv);

    // Only root can register bus
    if (getuid() != 0) {
        puts(_("System service should be started as root."));
        exit(1);
    }

    // Initialize main process
    if (proc_init(argc, argv, "Comar") != 0) {
        exit(1);
    }

    // Start logging
    if (log_start() != 0) {
        exit(1);
    }

    // Load models
    if (model_init() != 0) {
        exit(1);
    }

    // Initialize DB
    if (db_init() != 0) {
        exit(1);
    }

    while (!shutdown_activated) {
        // Listen for DBus calls
        dbus_listen();
        if (!shutdown_activated) {
            log_info("DBus connection is lost. Waiting 5 seconds and trying again...\n");
            sleep(5);
        }
    }

    model_free();
    proc_finish();

    return 0;
}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: hoglet67/b-em
void main_restart()
{
        bempause = 1;
        startblit();
        if (curtube == 3 || mouse_amx) remove_mouse();
        cmos_save(models[oldmodel]);
        oldmodel = curmodel;

        model_init();

        main_reset();

        if (curtube == 3 || mouse_amx) install_mouse();
        endblit();
        bempause = 0;
}
Ejemplo n.º 6
0
void docking_cleanup(struct dock_pak *dock, struct task_pak *task)
{
gchar *path, *ext;
GSList *list, *dir_list;
struct file_pak *file;
struct model_pak model;

/* temporary model data storage */
model_init(&model);

/* load gulp file energies into project */
/* TODO - scan for .res files */
/* TODO - if none - scan .got file for possible error reports */
path = dock->path;

/* scan project directory for .res files */
dir_list = file_dir_list(path, 0);
for (list=dir_list ; list ; list=g_slist_next(list))
  {
  file = get_file_info(list->data, BY_EXTENSION);
  if (file)
    {
    if (file->id == GULP)
      {
      ext  = find_char(list->data, '.', LAST);
      if (g_ascii_strncasecmp(ext, ".res", 3) == 0)
        {
/* process dump file */
        printf("%s\n", (gchar *) list->data);
        }
      }
    if (file->id == GULPOUT)
      {
/* process output file */

read_gulp_output(list->data, &model);

      printf("%s : %f\n", (gchar *) list->data, model.gulp.energy);
      }
    }
  }
/* cleanup */
g_slist_free(dir_list);
model_free(&model);
}
Ejemplo n.º 7
0
int
main (int argc, char *argv[])
{
  if (argc < 3)
    {
      fprintf (stderr, "missing command line arguments\n");
      return 1;
    }
  FILE *input = fopen (argv[1], "rb");
  assert (input != NULL);
  FILE *output = fopen (argv[2], "wb");
  assert (output != NULL);
  struct modelA cmodel;
  model_init (&cmodel);

  model_dump ();
  printf ("decompressing...\n");
  decompress (input, output, &cmodel);
  printf ("%" PRIu64 "\n", cmodel.m_bytesProcessed);
  fclose (input);
  fclose (output);
  return 0;
}
Ejemplo n.º 8
0
void resetpchard()
{
    if (!modelchanged)
        device_close_all();
    else
        modelchanged = 0;
    device_init();

    midi_close();
    midi_init();

    timer_reset();
    sound_reset();
    mem_resize();

    if (pcfirsttime)
    {
        fdc_init();
        pcfirsttime = 0;
    }
    else
        fdc_hard_reset();

    model_init();
    video_init();
    speaker_init();

// #ifdef USE_NETWORKING
    vlan_reset();	//NETWORK
    network_card_init(network_card_current);
// #endif

    sound_card_init(sound_card_current);
    if (GUS)
        device_add(&gus_device);
    if (GAMEBLASTER)
        device_add(&cms_device);
    if (SSI2001)
        device_add(&ssi2001_device);
    if (voodoo_enabled)
        device_add(&voodoo_device);
    pc_reset();

    resetide();

    loadnvr();

//        cpuspeed2 = (AT)?2:1;
//        atfullspeed = 0;
//        setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);

    shadowbios = 0;
    ali1429_reset();

    keyboard_at_reset();

//        output=3;

#if __unix
    if (cdrom_drive == -1)
        cdrom_null_reset();
    else
#endif
        ioctl_reset();
}
Ejemplo n.º 9
0
int 
main(void){
	
	SCS |= 0x01;
	
	FIODIR0 = 0;	/* Just to make sure that all pins on Port0 are input. */
	
	/* The following pins are output: */
	FIODIR0 |= ((1<<21) | BACKLIGHT_PWM_PIN | SOUND_ENABLE_PIN | (1<<6));
	
	/* TODO what is this pin for ? */
	FIODIR0 |= (1<<12);
	FIOSET0 = (1<<12);

	setSpeed(SPEED_30);
		
	rand_seed(13); 				// initialize the random number generator
	
	/* Initialize the kernel. Kernel is not running yet */
	kernel_init();

	/* Initialize the display */
	lcd_init(0);
	
	/* Initialize the serial port */
	serial_init(38400);
	task_add(&serial_out);					// Task 0
	
	/* Enable IRQs. Now IRQ service routines start to run */
	enableIRQ();
	
	/* Enable radio communication */
	RF_init();								// Task 1 == produce_send_token)

	/* Initialize backlight task */
	inactivity_cnt = 0;		// consider power on to be a user activity
	task_add(&backl_proc);					// Task 2
	startPWMIRQ();

	/* Initialize keyboard handling */
	key_init();								// Task 3 == key_scan()

	/* Build an initial model of the internal and external state of the world */
	model_init();							// Task 4 == update_playtime()
	
	/* Show something to the user depending on model */
	mainscreen_init();						// Task 5 == win_scroll_all()
	
	dbg("RESET");
	
	/* Start the controller task 
		- keeps model up to date
		- starts actions according to model
		- shows relevant information on the screen
	*/
	task_add(&controller);					// Task 6
											// Task 7 == assemble_line()
	
	/* Start the kernel scheduler */
	while(1){
		schedule();
	};

	return 0;
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: hoglet67/b-em
void main_init(int argc, char *argv[])
{
        char t[512], *p;
        int c;
        int tapenext = 0, discnext = 0;

        startblit();

        log_open();
        log_info("main: starting %s", VERSION_STR);

        vid_fskipmax = 1;

        al_init_main(argc, argv);

        append_filename(t, exedir, "roms/tube/ReCo6502ROM_816", 511);
        if (!file_exists(t,FA_ALL,NULL) && selecttube == 4) selecttube = -1;

        curtube = selecttube;
        model_check();

        for (c = 1; c < argc; c++)
        {
//                log_debug("%i : %s",c,argv[c]);
/*                if (!strcasecmp(argv[c],"-1770"))
                {
                        I8271=0;
                        WD1770=1;
                }
                else*/
//#ifndef WIN32
                if (!strcasecmp(argv[c], "--help"))
                {
                        printf("%s command line options :\n\n", VERSION_STR);
                        printf("-mx             - start as model x (see readme.txt for models)\n");
                        printf("-tx             - start with tube x (see readme.txt for tubes)\n");
                        printf("-disc disc.ssd  - load disc.ssd into drives :0/:2\n");
                        printf("-disc1 disc.ssd - load disc.ssd into drives :1/:3\n");
                        printf("-autoboot       - boot disc in drive :0\n");
                        printf("-tape tape.uef  - load tape.uef\n");
                        printf("-fasttape       - set tape speed to fast\n");
                        printf("-s              - scanlines display mode\n");
                        printf("-i              - interlace display mode\n");
                        printf("-debug          - start debugger\n");
                        printf("-allegro        - use Allegro for video rendering\n");
                        exit(-1);
                }
                else
//#endif
                if (!strcasecmp(argv[c], "-tape"))
                {
                        tapenext = 2;
                }
                else if (!strcasecmp(argv[c], "-disc") || !strcasecmp(argv[c], "-disk"))
                {
                        discnext = 1;
                }
                else if (!strcasecmp(argv[c], "-disc1"))
                {
                        discnext = 2;
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 'm' || argv[c][1] == 'M'))
                {
                        sscanf(&argv[c][2], "%i", &curmodel);
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 't' || argv[c][1] == 'T'))
                {
                        sscanf(&argv[c][2], "%i", &curtube);
                }
                else if (!strcasecmp(argv[c], "-fasttape"))
                {
                        fasttape = 1;
                }
                else if (!strcasecmp(argv[c], "-autoboot"))
                {
                        autoboot = 150;
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 'f' || argv[c][1]=='F'))
                {
                        sscanf(&argv[c][2], "%i", &vid_fskipmax);
            if (vid_fskipmax < 1) vid_fskipmax = 1;
            if (vid_fskipmax > 9) vid_fskipmax = 9;
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 's' || argv[c][1] == 'S'))
                {
                        vid_scanlines = 1;
                }
                else if (!strcasecmp(argv[c], "-debug"))
                {
                        debug_core = 1;
                }
                else if (!strcasecmp(argv[c], "-debugtube"))
                {
                        debug_tube = 1;
                }
                else if (argv[c][0] == '-' && (argv[c][1] == 'i' || argv[c][1] == 'I'))
                {
                        vid_interlace = 1;
            vid_linedbl = vid_scanlines = 0;
                }
                else if (tapenext)
                   strcpy(tape_fn, argv[c]);
                else if (discnext)
                {
                        strcpy(discfns[discnext-1], argv[c]);
                        discnext = 0;
                }
                else
                {
                    if ((p = strrchr(argv[c], '.')) && (!strcasecmp(p, ".uef") || !strcasecmp(p, ".csw"))) {
                        strncpy(tape_fn, argv[c], sizeof tape_fn);
                        tapenext = 0;
                    }
                    else {
                        strncpy(discfns[0], argv[c], sizeof discfns[0]);
                        discnext = 0;
                        autoboot = 150;
                    }
                }
                if (tapenext) tapenext--;
        }

        video_init();
        mode7_makechars();

#ifndef WIN32
        install_keyboard();
#endif
        install_timer();

        mem_init();
        ddnoise_init();
        tapenoise_init();

        sound_init();
        al_init();
        sid_init();
        sid_settype(sidmethod, cursid);
        music5000_init();

    adc_init();
#ifdef WIN32
        pal_init();
#endif
        disc_init();
        fdi_init();

        scsi_init();
        ide_init();
        vdfs_init();

        model_init();

        midi_init();
        main_reset();

        install_int_ex(secint, MSEC_TO_TIMER(1000));
        install_int_ex(int50,  MSEC_TO_TIMER(20));

        set_display_switch_mode(SWITCH_BACKGROUND);
#ifdef WIN32
                timeBeginPeriod(1);
#endif
        oldmodel = curmodel;

        if (curtube == 3 || mouse_amx) install_mouse();

        disc_load(0, discfns[0]);
        disc_load(1, discfns[1]);
        tape_load(tape_fn);
        if (defaultwriteprot) writeprot[0] = writeprot[1] = 1;

        endblit();

        debug_start();
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
    int i;
    float r = 0;
    Space *space;
    Entity *cube1,*cube2;
    char bGameLoopRunning = 1;
    Vec3D cameraPosition = {-10,3,0};
    Vec3D cameraRotation = {180,0,180};
    SDL_Event e;
    Obj *bgobj;
    Sprite *bgtext;

	//my variables
	Ship *playerShip;
	int specMode;
    
    init_logger("gametest3d.log");
    if (graphics3d_init(1024,768,1,"gametest3d",33) != 0)
    {
        return -1;
    }
    model_init();
    obj_init();
    entity_init(255);
	initShips();
    
    bgobj = obj_load("models/mountainvillage.obj");
    bgtext = LoadSprite("models/mountain_text.png",1024,1024);
    
    //cube1 = newCube(vec3d(0,0,0),"Cubert");
    //cube2 = newCube(vec3d(10,0,0),"Hobbes");
    
    //cube1->body.velocity.x = 0.1;
    
    space = space_new();
    space_set_steps(space,100);
    
    space_add_body(space,&cube1->body);
    space_add_body(space,&cube2->body);

	//my variables
	specMode = 0;
	numShips = 0;
	shipVel = 0;
	shipRot = 0;
	turretRot = 0;
	gunElev = 0;
	realTurrRot = 0;

	playerShip = spawnShip(space, vec3d(-10,0,0), 1);

    while (bGameLoopRunning)
    {
		updateAllShipPos();
		for (i = 0; i < 100;i++)
        {
			space_do_step(space);
        }
		updateAllShipComp();
		applyGrav();
		if(specMode == 0)
		{
			cameraPosition.x = playerShip->hull->body.position.x;
			cameraPosition.y = (playerShip->hull->body.position.y + 5);
			cameraPosition.z = playerShip->hull->body.position.z;
		}

        while ( SDL_PollEvent(&e) ) 
        {
            if (e.type == SDL_QUIT)
            {
                bGameLoopRunning = 0;
            }
            else if (e.type == SDL_KEYDOWN)
            {
                if (e.key.keysym.sym == SDLK_ESCAPE)
                {
                    bGameLoopRunning = 0;
                }
                else if (e.key.keysym.sym == SDLK_SPACE)
                {
                    cameraPosition.z++;
                }
                else if (e.key.keysym.sym == SDLK_z)
                {
                    cameraPosition.z--;
                }
                else if (e.key.keysym.sym == SDLK_w)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -sin(cameraRotation.z * DEGTORAD),
                            cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_s)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            sin(cameraRotation.z * DEGTORAD),
                            -cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_d)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            cos(cameraRotation.z * DEGTORAD),
                            sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_a)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -cos(cameraRotation.z * DEGTORAD),
                            -sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_LEFT)
                {
                    cameraRotation.y -= 1;
                }
                else if (e.key.keysym.sym == SDLK_RIGHT)
                {
                    cameraRotation.y += 1;
                }
                else if (e.key.keysym.sym == SDLK_UP)
                {
                    cameraRotation.x += 1;
                }
                else if (e.key.keysym.sym == SDLK_DOWN)
                {
                    cameraRotation.x -= 1;
                }
				

				
				else if (e.key.keysym.sym == SDLK_y && shipVel < 0.4)
                {
                    shipVel += 0.1;
                }
				else if (e.key.keysym.sym == SDLK_h && shipVel > 0.05)
                {
                    shipVel -= 0.1;
                }
				else if (e.key.keysym.sym == SDLK_j)
                {
                    shipRot += 0.5;
					if(shipRot >= 360){shipRot -= 360;}
                }
				else if (e.key.keysym.sym == SDLK_g)
                {
                    shipRot -= 0.5;
					if(shipRot < 0){shipRot += 360;}
                }
				else if (e.key.keysym.sym == SDLK_m && turretRot < 135)
                {
                    turretRot += 1;
                }
				else if (e.key.keysym.sym == SDLK_b && turretRot > -135)
                {
                    turretRot -= 1;
                }
				else if (e.key.keysym.sym == SDLK_o && gunElev < 50)
                {
                    gunElev += 0.5;
                }
				else if (e.key.keysym.sym == SDLK_l && gunElev > -5)
                {
                    gunElev -= 0.5;
                }
				else if (e.key.keysym.sym == SDLK_q)
                {
					if(specMode == 0){specMode = 1;}
					else {specMode = 0;}
                }
				else if (e.key.keysym.sym == SDLK_p)
                {
					fireBullet(space, playerShip->gun->body.position, realTurrRot, gunElev, 0.5, -1);
				}
				else if (e.key.keysym.sym == SDLK_x)
                {
					fireBullet(space, playerShip->hull->body.position, shipRot, 0, 0, -2);
				}
				else if (e.key.keysym.sym == SDLK_1)
                {
					startLevel(space, 1);
				}
				else if (e.key.keysym.sym == SDLK_2)
                {
					startLevel(space, 2);
				}
				else if (e.key.keysym.sym == SDLK_3)
                {
					startLevel(space, 3);
				}
            }
        }
		 
        graphics3d_frame_begin();
        
        glPushMatrix();
        set_camera(
            cameraPosition,
            cameraRotation);
        
        entity_draw_all();
		//updateAllShipModels();
        obj_draw(
            bgobj,
            vec3d(0,0,2),
            vec3d(90,90,0),
            vec3d(5,5,5),
            vec4d(1,1,1,1),
            bgtext
        );
        
        if (r > 360)r -= 360;
        glPopMatrix();
        /* drawing code above here! */
        graphics3d_next_frame();
    } 
    return 0;
}
Ejemplo n.º 12
0
int main(void)
{
	if(!glfwInit()) {
		printf("Could not init GLFW");
		getchar();
		return -1;
	}

	glfwWindowHint(GLFW_SAMPLES, 4);
	//Opengl 2.1
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
	//Opengl 3.3
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // MacOS fix
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	if(window_init(&window, 640, 480, "Test")) {
		fprintf( stderr, "Failed to open window.\n" );
		getchar();
		glfwTerminate();
	};

	window_set_size_callback(&window, window_size_callback);


	glewExperimental = GL_TRUE; // Needed for core profile
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "Failed to initialize GLEW\n");
		getchar();
		glfwTerminate();
		return -1;
	}
	//#clear errors GLEW may trigger
	printError();
	
	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

	GLuint VertexArrayID;
	glGenVertexArrays(1, &VertexArrayID);
	glBindVertexArray(VertexArrayID);


	//Load model
	//----------

	Model cube;
	model_init(&cube);
	model_set_data_length(&cube, sizeof(cube_vertex_data));
	model_set_vertices(&cube, cube_vertex_data);
	model_set_colors(&cube, cube_color_data);
	model_set_uv_map(&cube, cube_uv_data);
	model_set_texture(&cube, "./textures/bricks.dds");
	model_bind(&cube);


	//Create shaders
	//--------------
	
	GLuint vertexShader, fragmentShader;

	loadShader(&vertexShader, GL_VERTEX_SHADER, mvpVertexShaderSource);
	loadShader(&fragmentShader, GL_FRAGMENT_SHADER, fragmentShaderSource);


	//Create program
	//--------------

	GLuint program;
	createProgram(&program, vertexShader, fragmentShader);


	// Enable z-buffer
	// ---------------

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);


	// Enable culling
	// --------------

	glEnable(GL_CULL_FACE);


	// Get MVP uniform
	// ---------------

	GLuint mvp_ul = glGetUniformLocation(program, "MVP");


	// Model Matrix
	// ------------

	Mat4 s;
	scale_m4(&s, 0.1f, 0.1f, 0.1f);
	printf("Scale:\n");
	print_m4(&s);

	Mat4 r;
	rotate_m4(&r, 0.0f, 1.0f, 0.0f, 0.0f);
	printf("Rotate:\n");
	print_m4(&r);

	Mat4 t;
	translate_m4(&t, 0.0f, 0.0f, 0.0f);
	printf("Translate:\n");
	print_m4(&t);

	Mat4 rs;
	printf("Rotated*Scaled:\n");
	mul_m4(&rs, &r, &s);
	print_m4(&rs);

	Mat4 model;
	printf("Model:\n");
	mul_m4(&model, &t, &rs);
	print_m4(&model);


	// Camera
	// ------

	Vec3 pos;
	Vec3 center;
	Vec3 up;
	Vec3 direction;
	Vec3 right;

	camera_init(&camera);
	camera_set_fov(&camera, 1.0f);
	camera_set_aspect(&camera, (float)window.width/(float)window.height);
	
	Input input;
	input_init(&input, &window, 0.5f, 0.5f, 0.8f, -5.7f, -2.7f);

	do {
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

		glUseProgram(program);
		
		input_get_data(&input, &pos, &direction, &right);

		add_v3(&center, &pos, &direction);
		cross_v3(&up, &direction, &right);

		camera_set_position(&camera, &pos);
		camera_set_center(&camera, &center);
		camera_set_up(&camera, &up);


		// Mvp Matrix
		// ----------

		Mat4 vp;
		camera_get_matrix(&camera, &vp);

		Mat4 mvp;
		mul_m4(&mvp, &vp, &model);
		printf("Perspective:\n");
		print_m4(&mvp);


		// Set MVP transform
		glUniformMatrix4fv(mvp_ul, 1, GL_TRUE, &mvp[0][0]);

		model_render(&cube);

		window_swap_buffers(&window);
		glfwPollEvents();
	} while(
		glfwGetKey(window.handle, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
		glfwWindowShouldClose(window.handle) == 0
	);

	// Dispose
	// -------

	model_dispose(&cube);
	glDeleteVertexArrays(1, &VertexArrayID);
	glDetachShader(program, fragmentShader);
	glDetachShader(program, vertexShader);
	glDeleteShader(fragmentShader);
	glDeleteShader(vertexShader);
	glDeleteProgram(program);

	glfwTerminate();
	return 0;
}
Ejemplo n.º 13
0
Archivo: megahal.c Proyecto: lp0/sqlhal
static int megahal_learn(brain_t brain, list_t *input) {
	uint_fast32_t i;
	uint32_t size;
	number_t order;
	model_t *model;
	int ret;
	(void)brain;

	/* We only learn from inputs which are long enough */
	ret = db_model_get_order(brain, &order);
	if (ret) return ret;

	ret = list_size(input, &size);
	if (ret) return ret;

	if (size <= order) return OK;

	ret = model_alloc(brain, &model);
	if (ret) return ret;

	/*
	 * Train the model in the forwards direction. Start by initializing
	 * the context of the model.
	 */
	ret = model_init(model, MODEL_FORWARD);
	if (ret) goto fail;

	for (i = 0; i < size; i++) {
		word_t word;

		/* Get word symbol. */
		ret = list_get(input, i, &word);
		if (ret) goto fail;

		/* Update the forward model. */
		ret = model_update(model, word, 1);
		if (ret) goto fail;
	}

	/*
	 * Add the sentence-terminating symbol.
	 */
	ret = model_update(model, 0, 1);
	if (ret) goto fail;

	/*
	 * Train the model in the backwards direction. Start by initializing
	 * the context of the model.
	 */
	ret = model_init(model, MODEL_BACKWARD);
	if (ret) goto fail;

	for (i = 0; i < size; i++) {
		word_t word;

		/* Get word symbol. */
		ret = list_get(input, (size - 1) - i, &word);
		if (ret) goto fail;

		/* Update the backward model. */
		ret = model_update(model, word, 1);
		if (ret) goto fail;
	}

	/*
	 * Add the sentence-terminating symbol.
	 */
	ret = model_update(model, 0, 1);
	if (ret) goto fail;

	model_free(&model);
	return OK;

fail:
	model_free(&model);
	return ret;
}
Ejemplo n.º 14
0
void _main(int argc, char *argv[])
{
   (void)argc;
   (void)argv;
   syslog(LOG_INFO, "initializing core");
   
   /* init SCL subsystem: */
   syslog(LOG_INFO, "initializing signaling and communication link (SCL)");
   if (scl_init("core") != 0)
   {
      syslog(LOG_CRIT, "could not init scl module");
      exit(EXIT_FAILURE);
   }
   
   /* init params subsystem: */
   syslog(LOG_INFO, "initializing opcd interface");
   opcd_params_init("core.", 1);
   
   /* initialize logger: */
   syslog(LOG_INFO, "opening logger");
   if (logger_open() != 0)
   {
      syslog(LOG_CRIT, "could not open logger");
      exit(EXIT_FAILURE);
   }
   syslog(LOG_CRIT, "logger opened");
   sleep(1); /* give scl some time to establish
                a link between publisher and subscriber */

   LOG(LL_INFO, "+------------------+");
   LOG(LL_INFO, "|   core startup   |");
   LOG(LL_INFO, "+------------------+");

   LOG(LL_INFO, "initializing system");

   /* set-up real-time scheduling: */
   struct sched_param sp;
   sp.sched_priority = sched_get_priority_max(SCHED_FIFO);
   sched_setscheduler(getpid(), SCHED_FIFO, &sp);
   if (mlockall(MCL_CURRENT | MCL_FUTURE))
   {
      LOG(LL_ERROR, "mlockall() failed");
      exit(EXIT_FAILURE);
   }

   /* initialize hardware/drivers: */
   omap_i2c_bus_init();
   baro_altimeter_init();
   ultra_altimeter_init();
   ahrs_init();
   motors_init();
   voltage_reader_start();
   //gps_init();
   
   LOG(LL_INFO, "initializing model/controller");
   model_init();
   ctrl_init();
   
   /* initialize command interface */
   LOG(LL_INFO, "initializing cmd interface");
   cmd_init();
   
   /* prepare main loop: */
   for (int i = 0; i < NUM_AVG; i++)
   {
      output_avg[i] = sliding_avg_create(OUTPUT_RATIO, 0.0f);
   }

   LOG(LL_INFO, "system up and running");
   struct timespec ts_curr;
   struct timespec ts_prev;
   struct timespec ts_diff;
   clock_gettime(CLOCK_REALTIME, &ts_curr);
 
   /* run model and controller: */
   while (1)
   {
      /* calculate dt: */
      ts_prev = ts_curr;
      clock_gettime(CLOCK_REALTIME, &ts_curr);
      TIMESPEC_SUB(ts_diff, ts_curr, ts_prev);
      float dt = (float)ts_diff.tv_sec + (float)ts_diff.tv_nsec / (float)NSEC_PER_SEC;

      /* read sensor values into model input structure: */
      model_input_t model_input;
      model_input.dt = dt;
      ahrs_read(&model_input.ahrs_data);
      gps_read(&model_input.gps_data);
      model_input.ultra_z = ultra_altimeter_read();
      model_input.baro_z = baro_altimeter_read();

      /* execute model step: */
      model_state_t model_state;
      model_step(&model_state, &model_input);

      /* execute controller step: */
      mixer_in_t mixer_in;
      ctrl_step(&mixer_in, dt, &model_state);
 
      /* set up mixer input: */
      mixer_in.pitch = sliding_avg_calc(output_avg[AVG_PITCH], mixer_in.pitch);
      mixer_in.roll = sliding_avg_calc(output_avg[AVG_ROLL], mixer_in.roll);
      mixer_in.yaw = sliding_avg_calc(output_avg[AVG_YAW], mixer_in.yaw);
      mixer_in.gas = sliding_avg_calc(output_avg[AVG_GAS], mixer_in.gas);

      /* write data to motor mixer: */
      EVERY_N_TIMES(OUTPUT_RATIO, motors_write(&mixer_in));
   }
}
/*---------------------------------------------------------------------------*/
int
main(void)
{

  /* Hardware initialization */
  bus_init();
  rtimer_init();

  stack_poison();

  /* model-specific h/w init. */
  model_init();

  /* Init LEDs here */
  leds_init();
  fade(LEDS_GREEN);

  /* initialize process manager. */
  process_init();

  /* Init UART1 */
  uart1_init();

#if DMA_ON
  dma_init();
#endif

#if SLIP_ARCH_CONF_ENABLE
  /* On cc2430, the argument is not used */
  slip_arch_init(0);
#else
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif

  PUTSTRING("##########################################\n");
  putstring(CONTIKI_VERSION_STRING "\n");
  putstring(SENSINODE_MODEL " (CC24");
  puthex(((CHIPID >> 3) | 0x20));
  putstring("-" FLASH_SIZE ")\n");

#if STARTUP_VERBOSE
#ifdef HAVE_SDCC_BANKING
  PUTSTRING("  With Banking.\n");
#endif /* HAVE_SDCC_BANKING */
#ifdef SDCC_MODEL_LARGE
  PUTSTRING("  --model-large\n");
#endif /* SDCC_MODEL_LARGE */
#ifdef SDCC_MODEL_HUGE
  PUTSTRING("  --model-huge\n");
#endif /* SDCC_MODEL_HUGE */
#ifdef SDCC_STACK_AUTO
  PUTSTRING("  --stack-auto\n");
#endif /* SDCC_STACK_AUTO */

  PUTCHAR('\n');

  PUTSTRING(" Net: ");
  PUTSTRING(NETSTACK_NETWORK.name);
  PUTCHAR('\n');
  PUTSTRING(" MAC: ");
  PUTSTRING(NETSTACK_MAC.name);
  PUTCHAR('\n');
  PUTSTRING(" RDC: ");
  PUTSTRING(NETSTACK_RDC.name);
  PUTCHAR('\n');

  PUTSTRING("##########################################\n");
#endif

  watchdog_init();

  /* Initialise the cc2430 RNG engine. */
  random_init(0);

  /* start services */
  process_start(&etimer_process, NULL);
  ctimer_init();

  /* initialize the netstack */
  netstack_init();
  set_rime_addr();

#if BUTTON_SENSOR_ON || ADC_SENSOR_ON
  process_start(&sensors_process, NULL);
  sensinode_sensors_activate();
#endif

#if UIP_CONF_IPV6
  memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr));
  queuebuf_init();
  process_start(&tcpip_process, NULL);

#if DISCO_ENABLED
  process_start(&disco_process, NULL);
#endif /* DISCO_ENABLED */

#if VIZTOOL_CONF_ON
  process_start(&viztool_process, NULL);
#endif

#if (!UIP_CONF_IPV6_RPL)
  {
    uip_ipaddr_t ipaddr;

    uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
  }
#endif /* UIP_CONF_IPV6_RPL */
#endif /* UIP_CONF_IPV6 */

  /*
   * Acknowledge the UART1 RX interrupt
   * now that we're sure we are ready to process it
   */
  model_uart_intr_en();

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  fade(LEDS_RED);

#if BATMON_CONF_ON
  process_start(&batmon_process, NULL);
#endif

  autostart_start(autostart_processes);

  watchdog_start();

  while(1) {
    uint8_t r;
    do {
      /* Reset watchdog and handle polls and events */
      watchdog_periodic();

#if CLOCK_CONF_STACK_FRIENDLY
      if(sleep_flag) {
        if(etimer_pending() &&
            (etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) {
          etimer_request_poll();
        }
        sleep_flag = 0;
      }
#endif
      r = process_run();
    } while(r > 0);
#if NETSTACK_CONF_SHORTCUTS
    len = NETSTACK_RADIO.pending_packet();
    if(len) {
      packetbuf_clear();
      len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
      if(len > 0) {
        packetbuf_set_datalen(len);
        NETSTACK_RDC.input();
      }
    }
#endif

#if LPM_MODE
#if (LPM_MODE==LPM_MODE_PM2)
    SLEEP &= ~OSC_PD;            /* Make sure both HS OSCs are on */
    while(!(SLEEP & HFRC_STB));  /* Wait for RCOSC to be stable */
    CLKCON |= OSC;               /* Switch to the RCOSC */
    while(!(CLKCON & OSC));      /* Wait till it's happened */
    SLEEP |= OSC_PD;             /* Turn the other one off */
#endif /* LPM_MODE==LPM_MODE_PM2 */

    /*
     * Set MCU IDLE or Drop to PM1. Any interrupt will take us out of LPM
     * Sleep Timer will wake us up in no more than 7.8ms (max idle interval)
     */
    SLEEP = (SLEEP & 0xFC) | (LPM_MODE - 1);

#if (LPM_MODE==LPM_MODE_PM2)
    /*
     * Wait 3 NOPs. Either an interrupt occurred and SLEEP.MODE was cleared or
     * no interrupt occurred and we can safely power down
     */
    __asm
      nop
      nop
      nop
    __endasm;

    if (SLEEP & SLEEP_MODE0) {
#endif /* LPM_MODE==LPM_MODE_PM2 */

      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);

      /* We are only interested in IRQ energest while idle or in LPM */
      ENERGEST_IRQ_RESTORE(irq_energest);

      /* Go IDLE or Enter PM1 */
      PCON |= IDLE;

      /* First instruction upon exiting PM1 must be a NOP */
      __asm
        nop
      __endasm;

      /* Remember energest IRQ for next pass */
      ENERGEST_IRQ_SAVE(irq_energest);

      ENERGEST_ON(ENERGEST_TYPE_CPU);
      ENERGEST_OFF(ENERGEST_TYPE_LPM);

#if (LPM_MODE==LPM_MODE_PM2)
      SLEEP &= ~OSC_PD;            /* Make sure both HS OSCs are on */
      while(!(SLEEP & XOSC_STB));  /* Wait for XOSC to be stable */
      CLKCON &= ~OSC;              /* Switch to the XOSC */
      /*
       * On occasion the XOSC is reported stable when in reality it's not.
       * We need to wait for a safeguard of 64us or more before selecting it
       */
      clock_delay_usec(65);
      while(CLKCON & OSC);         /* Wait till it's happened */
    }
#endif /* LPM_MODE==LPM_MODE_PM2 */
#endif /* LPM_MODE */
  }
}
Ejemplo n.º 16
0
//extern void drawModelSetMax(void);
int glInit(void){
	cvar_register(&cvar_gl_MSAA_Samples);
	cvar_pset(&cvar_gl_MSAA_Samples, "0");
//	console_printf("cvar id is %i\n", cvar_gl_MSAA_Samples.myid);
//	console_printf("cvar name is %s\n", cvar_gl_MSAA_Samples.name);
//	console_printf("cvar value is %s\n", cvar_gl_MSAA_Samples.valuestring);
	glewExperimental = TRUE;
	GLenum glewError = glewInit();
	CHECKGLERROR
	if(glewError != GLEW_OK){
		console_printf("ERROR with the glew: %s\n", glewGetErrorString(glewError));
		return FALSE;
	}
	shader_init();
	CHECKGLERROR
	if(!shader_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
	texture_init();
	CHECKGLERROR
	if(!texture_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
	framebuffer_init();
	CHECKGLERROR
	if(!framebuffer_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
	vbo_init();
	CHECKGLERROR
	if(!vbo_ok){
		return FALSE;
		//todo call some sort of shutdown of everything
	}
	ubo_init();
	CHECKGLERROR
	if(!ubo_ok){
		return FALSE;
		//todo call some sort of shutdown of everything
	}
	anim_init();
	CHECKGLERROR
	if(!anim_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	model_init();
	CHECKGLERROR
	if(!model_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
/*
	initParticleSystem(128);
	if(!particlesOK){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
*/
	light_init();
	CHECKGLERROR
	if(!light_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	lighttile_init();
	CHECKGLERROR
	if(!lighttile_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	viewport_init();
	CHECKGLERROR
	if(!viewport_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	text_init();
	CHECKGLERROR
	if(!text_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	rendermodel_init();
	CHECKGLERROR
	//todo errorcheck
	drawbb_init();
	CHECKGLERROR
	//todo errorcheck

	states_enableForce(GL_MULTISAMPLE);
	glClearDepth(1.0);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	CHECKGLERROR
//	states_disableForce(GL_FOG);
	states_enableForce(GL_DEPTH_TEST);
	CHECKGLERROR
//	glDepthFunc(GL_LESS);
	states_depthFunc(GL_LESS);
	states_enableForce(GL_CULL_FACE);
	states_cullFace(GL_BACK);
//	states_depthMask(GL_TRUE);

	int maxSamples = 0, maxIntSamples = 0, maxColorTextureSamples = 0, maxDepthTextureSamples = 0;
	glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
	glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &maxIntSamples);
	glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxColorTextureSamples);
	glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &maxDepthTextureSamples);
	maxMSAASamples = maxSamples;
	if(maxIntSamples < maxMSAASamples) maxMSAASamples = maxIntSamples;
	if(maxColorTextureSamples < maxMSAASamples) maxMSAASamples = maxColorTextureSamples;
	if(maxDepthTextureSamples < maxMSAASamples) maxMSAASamples = maxDepthTextureSamples;
	console_printf("Max multisample samples: %i\n", maxMSAASamples);


	cam = createAndAddViewportRPOINT("cam", 1);
	camid = cam->myid;
	cam->outfbid = findFramebufferByNameRINT("screen");

	unsigned char dflags[] = {3, 7, 3};
//	unsigned char drb = FRAMEBUFFERRBFLAGSDEPTH| 2;
	unsigned char drb = FRAMEBUFFERRBFLAGSDEPTH;
	unsigned char dcount = 3;
	cam->dfbid = createAndAddFramebufferRINT("screend", dcount, drb, dflags);
	resizeViewport(cam, 800, 600);
	screenWidth = 800;
	screenHeight = 600;

	glGenBuffers(1, &instancevbo);
	glGenBuffers(1, &instancevbo2);

	//temporary
	CHECKGLERROR
	vbo_t * tvbo = createAndAddVBORPOINT("text", 2);
	textvbo = tvbo->myid;
	textshaderid = shader_createAndAddRINT("text");
	fsblendshaderid = shader_createAndAddRINT("fsblend");
	depthonlyid = shader_createAndAddRINT("depthmodel");
	forwardmodelid = shader_createAndAddRINT("forwardmodel");
	fsquadmodel = model_findByNameRINT("fsquad");

	readyRenderQueueBuffers();



	return TRUE; // so far so good
}
Ejemplo n.º 17
0
int main(int argc, char *argv[])
{
    int i;
    float r = 0;
	int f = -15;
	int g = 0;
	int l = 0;
	int y = 0;
	int u = 15;
	int q = 0;
	int gamestate=0;
	int PlayerHP=15, Bosshealth=30, enemy1health=5, enemy2health=5, Bigtimer=600, CD;
	int SpawnLemon1=0, SpawnLemon2=0, SpawnLemon3=0, SpawnBigLemon=0, enemybullet=0;
	float Lemonx1=0, Lemonx2=0, Lemonx3=0, LemonxBig=0, enemybulletx=0;
	int Lemony1=0, Lemony2=0, Lemony3=0, LemonyBig=0, enemybullety=0;
	int a=0, b=0, c=0, d=0, count, Goomba_attack1=0, Goomba_attack2=0, Goomba_move1, Goomba_move2;
    Space *space;
    Entity *cube1,*cube2, *Actor;
    char bGameLoopRunning = 1;
	Vec3D Bosspos = {u, y, 2};
	Vec3D enemy1pos = {5, 10, 2};
	Vec3D enemy2pos = {5, -10, 2};
    Vec3D cameraPosition = {0,0,70.3};
    Vec3D cameraRotation = {0,0,360};
    SDL_Event e;
    Obj *megaman,*boss, *mapp, *mape, *lemon, *BossHPBar, *PlayerHPBar, *Goomba;
    Sprite *megamantexture, *bosstexture, *maptexture1, *maptexture2, *lemontexture, *BosstextureHP, *PlayertextureHP, *Goombatexture;
    
    init_logger("gametest3d.log");
    if (graphics3d_init(1024,768,1,"gametest3d",33) != 0)
    {
        return -1;
    }
    model_init();
    obj_init();
    entity_init(255);
    
   //load objects, models here, replace cube with megaman
    megaman = obj_load("models/MPU.obj");
	//load his uv map "texture file"
    megamantexture = LoadSprite("models/MegaManBody1.png",1024,1024);

	PlayerHPBar = obj_load("models/cube.obj");
	PlayertextureHP = NULL;


	boss = obj_load("models/Fireman.obj");
	bosstexture = LoadSprite("models/FireManBody1.png",1024,1024);

	BossHPBar = obj_load("models/cube.obj");
	BosstextureHP = NULL;

	Goomba = obj_load("models/goomba.obj");
	Goombatexture = LoadSprite("models/goomba_tex.png",1024,1024);

    mapp = obj_load("models/MidtermMapSingle.obj");
	maptexture1 = LoadSprite("models/PlayerTile(Red).png",1024,1024);

	mape = obj_load("models/MidtermMapSingle.obj");
	maptexture2 = LoadSprite("models/BossTile(Blue).png",1024,1024);
    
    lemon = obj_load("models/cube.obj");
	lemontexture = NULL;//LoadSprite("models/cube_text.png",1024,1024);
    
	    
    while (bGameLoopRunning)
    {
        entity_think_all();

        while ( SDL_PollEvent(&e) ) 
        {
            if (e.type == SDL_QUIT)
            {
                bGameLoopRunning = 0;
            }
            else if (e.type == SDL_KEYDOWN)
            {
                if (e.key.keysym.sym == SDLK_ESCAPE)
                {
                    bGameLoopRunning = 0;
                }
                else if (e.key.keysym.sym == SDLK_x)
                {
                    cameraPosition.z++;
                }
                else if (e.key.keysym.sym == SDLK_z)
                {
                    cameraPosition.z--;
                }
                else if (e.key.keysym.sym == SDLK_h)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -sin(cameraRotation.z * DEGTORAD),
                            cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_y)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            sin(cameraRotation.z * DEGTORAD),
                            -cos(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_j)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            cos(cameraRotation.z * DEGTORAD),
                            sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
                else if (e.key.keysym.sym == SDLK_g)
                {
                    vec3d_add(
                        cameraPosition,
                        cameraPosition,
                        vec3d(
                            -cos(cameraRotation.z * DEGTORAD),
                            -sin(cameraRotation.z * DEGTORAD),
                            0
                        ));
                }
				else if (e.key.keysym.sym == SDLK_d)
                {
                   
				   
				   if(f >= -5)
				   {
					   f = -5;
				   }
				   else
				   {
					   f += 10;
				   }
                }
				else if (e.key.keysym.sym == SDLK_a)
                {
                   
				   
				   if(f <= -20)
				   {
					   f = -25;
				   }
				   else
				   {
					   f -= 10;
				   }
				  			
                }
				else if (e.key.keysym.sym == SDLK_w)
                {
                   
				   if(g >= 5)
				   {
					   g = 10;
				   }
				   else
				   {
					   g += 10;
				   }
			
                }
				else if (e.key.keysym.sym == SDLK_s)
                {
                   
				   g -= 10;
				    if(g <= -5)
				   {
					   g = -10;
				   }
			
                }
                else if (e.key.keysym.sym == SDLK_LEFT)
                {
                    cameraRotation.z += 1;
                }
                else if (e.key.keysym.sym == SDLK_RIGHT)
                {
                    cameraRotation.z -= 1;
                }
                else if (e.key.keysym.sym == SDLK_UP)
                {
                    cameraRotation.x += 1;
                }
                else if (e.key.keysym.sym == SDLK_DOWN)
                {
                    cameraRotation.x -= 1;
                }
                else if (e.key.keysym.sym == SDLK_SPACE)
                {
                    
					CD = TIME + Bigtimer;					
					
                }
				else if (e.key.keysym.sym == SDLK_n)
                {
                   
				   if (enemy1health <= 0 && enemy2health <= 0)
				   {
					   gamestate=1;
				   }
			
                }
				else if (e.key.keysym.sym == SDLK_n)
                {
                   
				   if (enemy1health <= 0 && enemy2health <= 0)
				   {
					   gamestate=1;
				   }
			
                }
            }
			else if (e.type == SDL_KEYUP)
			{
				if (e.key.keysym.sym == SDLK_SPACE)
				{
					
					if (TIME >= CD && SpawnBigLemon !=1)
					{
						SpawnBigLemon = 1;
						LemonxBig = f;
						LemonyBig = g;
					}
					else if (SpawnLemon1 != 1)
					{
						SpawnLemon1 = 1;
						Lemonx1 = f;
						Lemony1 = g;
					}
					else if (SpawnLemon2 != 1)
					{
						SpawnLemon2 = 1;
						Lemonx2 = f;
						Lemony2 = g;
					}
					else if (SpawnLemon3 != 1)
					{
						SpawnLemon3 = 1;
						Lemonx3 = f;
						Lemony3 = g;
					}
					
				}
			}
				
        }

                
        graphics3d_frame_begin();
        
        glPushMatrix();
        set_camera(
            cameraPosition,
            cameraRotation);
        
        //entity_draw_all();
      
		if (PlayerHP > 0 )
		{
		//Megaman
        obj_draw(
            megaman,
            vec3d(f, g, 2),
            vec3d(90,90,0),
            vec3d(0.5,0.5,0.5),
            vec4d(1,1,1,1),
            megamantexture
        );

		//Megaman HP BAR
		obj_draw(
            PlayerHPBar,
            vec3d(-30+PlayerHP/(2),20,2),
            vec3d(90,-90,0),
            vec3d(.9,.9,PlayerHP/(2)),
            vec4d(0,1,0,1),
			PlayertextureHP
        );
		}

		//Megaman Projectiles
		//Lemon1
		if (SpawnLemon1 != 0)
		{
			obj_draw(
			lemon,
            vec3d(Lemonx1 + a*(.4), Lemony1, 4),
            vec3d(90,90,0),
            vec3d(1,1,2),
            vec4d(.95,.89,0,1),
		    lemontexture
		);
			a++;
				if (Lemonx1 + a*(.4) >=30)
				{
					SpawnLemon1 = 0;
					a=0;
				}
				else if (Lemonx1 + a*(.4) == enemy1pos.x && Lemony1 == enemy1pos.y)
				{
					SpawnLemon1 = 0;
					a=0;
					enemy1health -= 1;
					//slog("Enemy Health %d",enemy1health);
				}
				else if (Lemonx1 + a*(.4) == enemy2pos.x && Lemony1 == enemy2pos.y)
				{
					SpawnLemon1 = 0;
					a=0;
					enemy2health -= 1;
					//slog("Enemy Health %d",enemy2health);
				}
				else if (gamestate == 1 && Lemonx1 + a*(.4) == Bosspos.x && Lemony1 == Bosspos.y)
				{
				SpawnLemon1 = 0;
				a=0;
				Bosshealth -= 1;
				//slog("Boss Health %d",Bosshealth);
				}
		}
		//Lemon2
		if (SpawnLemon2 != 0)
		{
			obj_draw(
			lemon,
            vec3d(Lemonx2 + b*(.4), Lemony2, 4),
            vec3d(90,90,0),
            vec3d(1,1,2),
            vec4d(.95,.89,0,1),
		    lemontexture
		);
			b++;
				if (Lemonx2 + b*(.4) >=30)
				{
					SpawnLemon2 = 0;
					b=0;
				}
				else if (Lemonx2 + b*(.4) == enemy1pos.x && Lemony2 == enemy1pos.y)
				{
					SpawnLemon2 = 0;
					b=0;
					enemy1health -= 1;
					//slog("Enemy Health %d",enemy1health);
				}
				else if (Lemonx2 + b*(.4) == enemy2pos.x && Lemony2 == enemy2pos.y)
				{
					SpawnLemon2 = 0;
					b=0;
					enemy2health -= 1;
					//slog("Enemy Health %d",enemy2health);
				}
				else if (gamestate == 1 && Lemonx2 + b*(.4) == Bosspos.x && Lemony2 == Bosspos.y)
				{
					SpawnLemon2 = 0;
					b=0;
					Bosshealth -= 1;
					//slog("Boss Health %d",Bosshealth);
				}
		}
		if (SpawnLemon3 != 0)
		{
			obj_draw(
			lemon,
            vec3d(Lemonx3 + c*(.4), Lemony3, 4),
            vec3d(90,90,0),
            vec3d(1,1,2),
            vec4d(.95,.89,0,1),
		    lemontexture
		);
			c++;
				//lemons fly off staege
				if (Lemonx3 + c*(.4) >=30)
				{
					SpawnLemon3 = 0;
					c=0;
				}
				//lemons collide with enemies
				else if (Lemonx3 + c*(.4) == enemy1pos.x && Lemony3 == enemy1pos.y)
				{
					SpawnLemon3 = 0;
					c=0;
					enemy1health -= 1;
					slog("Enemy Health %d",enemy1health);
				}
				else if (Lemonx3 + c*(.4) == enemy2pos.x && Lemony3 == enemy2pos.y)
				{
					SpawnLemon3 = 0;
					c=0;
					enemy2health -= 1;
					slog("Enemy Health %d",enemy2health);
				}
				else if (gamestate == 1 && Lemonx3 + c*(.4) == Bosspos.x && Lemony3 == Bosspos.y)
				{
					SpawnLemon3 = 0;
					c=0;
					Bosshealth -= 1;
					//slog("Boss Health %d",Bosshealth);
				}
		}
		if (SpawnBigLemon != 0)
		{
			obj_draw(
			lemon,
            vec3d(LemonxBig + d*(.4), LemonyBig, 4),
            vec3d(90,90,0),
            vec3d(2,2,4),
            vec4d(.9,.3,.1,1),
		    lemontexture
		);
			d++;
				if (LemonxBig + d*(.4) >=30)
				{
					SpawnBigLemon = 0;
					d=0;
				}
				else if (LemonxBig + d*(.4) == enemy1pos.x && LemonyBig == enemy1pos.y)
				{
					SpawnBigLemon = 0;
					d=0;
					enemy1health -= 5;
					//slog("Enemy Health %d",enemy1health);
				}
				else if (LemonxBig + d*(.4) == enemy2pos.x && LemonyBig == enemy2pos.y)
				{
					SpawnBigLemon = 0;
					d=0;
					enemy2health -= 5;
					//slog("Enemy Health %d",enemy2health);
				}
				else if (gamestate == 1 && LemonxBig + d*(.4) == Bosspos.x && LemonyBig == Bosspos.y)
				{
					SpawnBigLemon = 0;
					d=0;
					Bosshealth -= 5;
					slog("Boss Health %d",Bosshealth);
				}
		}

		
		//MAP
		obj_draw(
            mapp,
            vec3d(-15,0,2),
            vec3d(90,90,0),
            vec3d(5,5,5),
            vec4d(1,1,1,1),
		    maptexture1
		);
		obj_draw(
            mape,
            vec3d(15,0,2),
            vec3d(90,90,0),
            vec3d(5,5,5),
            vec4d(1,1,1,1),
		    maptexture2
		);
		

		//Enemies
		if (gamestate == 0)
		{

			if (enemy1health > 0)
			{
			//enemy_move(enemypos.x,enemypos.y, &enemypos);
			//enemy_attack1(Goomba_attack1, &enemy1pos);

			obj_draw(
            Goomba,
            vec3d(enemy1pos.x,enemy1pos.y,2),
            vec3d(90,-90,0),
            vec3d(0.1,0.1,0.1),
            vec4d(1,1,1,1),
            Goombatexture
			);
						
			if (Goomba_attack1 == 0)
			{
				Goomba_attack1 = rand_ranged( 1, 5); //start to (end - 1)
				if (Goomba_attack1 == 2)
				{
					Goomba_attack1 = 1;
				}
		
			};

			if (Goomba_attack1 == 1)
			{
				enemy1pos.x -=.1;
				if (enemy1pos.x <= -30)
				{
					Goomba_attack1 = 0;
					enemy1pos.x = 5;
				}
			}

			}
			else
			{
				enemy1pos.x = 50;
				enemy1pos.y = 50;
			}

			if (enemy2health > 0)
			{
			//enemy_move(enemypos.x,enemypos.y, &enemypos);
			//enemy_attack2(Goomba_attack2, &enemy2pos);
			obj_draw(
            Goomba,
            vec3d(enemy2pos.x,enemy2pos.y,2),
            vec3d(90,-90,0),
            vec3d(0.1,0.1,0.1),
            vec4d(1,1,1,1),
            Goombatexture
			);

			//bottom Goomba won't attack

			if (Goomba_attack2 == 0)
			{
				Goomba_attack2 = rand_ranged( 1, 5); //start to (end - 1)
				if (Goomba_attack2 == 2)
				{
					Goomba_attack2 = 1;
				}
		
			};

			if (Goomba_attack2 == 1)
			{
				enemy2pos.x -=.1;
				if (enemy2pos.x <= -30)
				{
					Goomba_attack2 = 0;
					enemy2pos.x = 5;
				}
			}

			
			}
			else
			{
				enemy2pos.x = 50;
				enemy2pos.y = 50;
			}
			
		}
		if (gamestate != 0)
		{
		if (Bosshealth > 0)
		{
			Boss_move(Bosspos.x,Bosspos.y, &Bosspos);      	    
			//Fire man
			obj_draw(
				boss,
				vec3d(Bosspos.x,Bosspos.y,2),
				vec3d(90,-90,0),
				vec3d(0.5,0.5,0.5),
				vec4d(1,1,1,1),
				bosstexture
				);

				obj_draw(
				BossHPBar,
				vec3d(30-Bosshealth/(2.5),20,2),
				vec3d(90,-90,0),
				vec3d(.9,.9,Bosshealth/(2.5)),
				vec4d(1,0,0,1),
				BosstextureHP
			);

		}
		else
		{
			obj_free(boss);

			Bosspos.x = 50;
			Bosspos.y = 50;
			slog("You WIN!");
		}
		

		}
        
        if (r > 360)r -= 360;
        glPopMatrix();
        /* drawing code above here! */
        graphics3d_next_frame();
	} 
	return 0;
	}