Exemple #1
0
bool newbrain_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
{
	if (m_enrg1 & NEWBRAIN_ENRG1_TVP)
	{
		screen_update(&bitmap, &cliprect);
	}
	else
	{
		bitmap_fill(&bitmap, &cliprect, get_black_pen(m_machine));
	}

	return 0;
}
Exemple #2
0
UINT32 newbrain_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	if (m_enrg1 & NEWBRAIN_ENRG1_TVP)
	{
		screen_update(bitmap, cliprect);
	}
	else
	{
		bitmap.fill(get_black_pen(machine()), cliprect);
	}

	return 0;
}
Exemple #3
0
uint32_t newbrain_state::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	if (m_tvp)
	{
		screen_update(bitmap, cliprect);
	}
	else
	{
		bitmap.fill(rgb_t::black(), cliprect);
	}

	return 0;
}
Exemple #4
0
static void *
neighbor_callback(const interface *i,struct l2host *l2){
	void *ret;

	pthread_mutex_lock(&bfl);
	if( (ret = neighbor_callback_locked(i,l2)) ){
		if(active){
			assert(top_panel(active->p) != ERR);
		}
		screen_update();
	}
	pthread_mutex_unlock(&bfl);
	return ret;
}
Exemple #5
0
void screen_test(void) {
    uint32_t x;
    while (1) {
        for (x = 0; x < 64; x++) {
            screen_clear();
            screen_puts_xy(0,  x+0, 1, "0 ABC");
            screen_puts_xy(30, x+1, 1, "1 ABC");
            screen_puts_xy(60, x+2, 1, "2 ABC");
            screen_puts_xy(90, x+3, 1, "3 ABC");
            screen_update();

            delay_ms(100);
        }
    }
}
Exemple #6
0
static void *
service_callback(const interface *i,struct l2host *l2,struct l3host *l3,
				struct l4srv *l4){
	void *ret;

	pthread_mutex_lock(&bfl);
	if( (ret = service_callback_locked(i,l2,l3,l4)) ){
		if(active){
			assert(top_panel(active->p) != ERR);
		}
		screen_update();
	}
	pthread_mutex_unlock(&bfl);
	return ret;
}
int main(void)
{
	device_t device;
	int states[] = { RENDER_STATE_TEXTURE, RENDER_STATE_COLOR, RENDER_STATE_WIREFRAME };
	int indicator = 0;
	int kbhit = 0;
	float alpha = 1;
	float pos = 3.5;

	TCHAR *title = _T("Mini3d (software render tutorial) - ")
		_T("Left/Right: rotation, Up/Down: forward/backward, Space: switch state");

	if (screen_init(800, 600, title))
		return -1;

	device_init(&device, 800, 600, screen_fb);
	camera_at_zero(&device, 3, 0, 0);

	init_texture(&device);
	device.render_state = RENDER_STATE_TEXTURE;

	while (screen_exit == 0 && screen_keys[VK_ESCAPE] == 0) {
		screen_dispatch();
		device_clear(&device, 1);
		camera_at_zero(&device, pos, 0, 0);

		if (screen_keys[VK_UP]) pos -= 0.01f;
		if (screen_keys[VK_DOWN]) pos += 0.01f;
		if (screen_keys[VK_LEFT]) alpha += 0.01f;
		if (screen_keys[VK_RIGHT]) alpha -= 0.01f;

		if (screen_keys[VK_SPACE]) {
			if (kbhit == 0) {
				kbhit = 1;
				if (++indicator >= 3) indicator = 0;
				device.render_state = states[indicator];
			}
		}
		else {
			kbhit = 0;
		}

		draw_box(&device, alpha);
		screen_update();
		Sleep(1);
	}
	return 0;
}
void screen_char32x16(int32_t ch, int32_t row, int32_t col)
{
  ////int32_t	h, i, j, k, q, r, s, mask, cbase, cset, bset;
  int32_t	h, j, k, r, mask, cbase, bset;
  if ((row == 0) || ((row == 1) && ((col >= 0) && (col < 8)))) 
  {
    // Write a 16x32 character to the screen at position 0-7 (left to right)
    // Compute the base of the interleaved character 
    cbase = 32768 + ((ch & 0xfe) << 6);
    for(j = 0; j <= 31; j++) {
      // For all the rows in the font
      // For setting bits in the OLED buffer. The mask is always a byte and has to wrap
      bset = (1<<(j % 8));
      if (ch & 0x1) {
        // For the extraction of the bits interleaved in the font
        mask = 2;
      } else {
        // For the extraction of the bits interleaved in the font
        mask = 1;
      }
      // Row is the font data with which to perform bit extraction
      r = ((int32_t *)cbase)[j];
      // Just for printing the font  to the serial terminal (DEBUG)
      //s = 0;
      // Get the base address of the OLED buffer
      h = (int32_t)(&self->buffer[0]) + (row * 512);
      // Compute the offset to the column of data and add to the base...
      h = h + (((Shr__(j, 3)) * 128) + (col * 16));
      // ...then add the offset to the character position
      for(k = 0; k <= 15; k++) {
        // For all 16 bits we need from the interlaced font...
        if (r & mask) {
          // Set the column bit
          ((uint8_t *)h)[k] = ((uint8_t *)h)[k] | bset;
        } else {
          // Clear the column bit
          ((uint8_t *)h)[k] = ((uint8_t *)h)[k] & (~bset);
        }
        // The mask shifts two places because the fonts are interlaced
        mask = mask << 2;
      }
    }
    if (self->AutoUpdate) screen_update();
    self->crsrX = col;
    self->crsrY = row;
  }
}
Exemple #9
0
/**
 * mate_rr_screen_refresh
 * @screen: a #MateRRScreen
 * @error: location to store error, or %NULL
 *
 * Refreshes the screen configuration, and calls the screen's callback if it
 * exists and if the screen's configuration changed.
 *
 * Return value: TRUE if the screen's configuration changed; otherwise, the
 * function returns FALSE and a NULL error if the configuration didn't change,
 * or FALSE and a non-NULL error if there was an error while refreshing the
 * configuration.
 */
gboolean
mate_rr_screen_refresh (MateRRScreen *screen,
			 GError       **error)
{
    gboolean refreshed;

    g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

    gdk_x11_display_grab (gdk_screen_get_display (screen->gdk_screen));

    refreshed = screen_update (screen, FALSE, TRUE, error);
    force_timestamp_update (screen); /* this is to keep other clients from thinking that the X server re-detected things by itself - bgo#621046 */

    gdk_x11_display_ungrab (gdk_screen_get_display (screen->gdk_screen));

    return refreshed;
}
void Draw(void)
{
  clear();

  cursor(6, 7);
  string("Score");

  cursor(0, 7);
  letter( '0' + Score[0] );

  cursor(15, 7);
  letter( '0' + Score[1] );

  box(0, 1, Width*2, Height*2+1, 1);
  point(BallX + HCenter, BallY + VCenter, 1);
  line( HCenter-PadRow, VCenter + Paddle[0] - PadLen,  HCenter-PadRow, VCenter + Paddle[0] + PadLen, 1 );
  line( HCenter+PadRow, VCenter + Paddle[1] - PadLen,  HCenter+PadRow, VCenter + Paddle[1] + PadLen, 1 );

  screen_update();
}
Exemple #11
0
static void
do_mpd_update(void)
{
	if (mpdclient_is_connected(mpd) &&
	    (mpd->source == NULL || mpd->events != 0 ||
	     (mpd->status != NULL &&
	      mpd_status_get_state(mpd->status) == MPD_STATE_PLAY)))
		mpdclient_update(mpd);

#ifndef NCMPC_MINI
	if (options.enable_xterm_title)
		update_xterm_title();
#endif

	screen_update(mpd);
	mpd->events = 0;

	mpdclient_put_connection(mpd);
	check_reconnect();
}
Exemple #12
0
/**
 * gnome_rr_screen_refresh:
 * @screen: a #GnomeRRScreen
 * @error: location to store error, or %NULL
 *
 * Refreshes the screen configuration, and calls the screen's callback if it
 * exists and if the screen's configuration changed.
 *
 * Return value: TRUE if the screen's configuration changed; otherwise, the
 * function returns FALSE and a NULL error if the configuration didn't change,
 * or FALSE and a non-NULL error if there was an error while refreshing the
 * configuration.
 */
gboolean
gnome_rr_screen_refresh (GnomeRRScreen *screen,
			 GError       **error)
{
    gboolean refreshed;

    g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

#ifdef HAVE_X11
    gdk_x11_display_grab (gdk_screen_get_display (screen->priv->gdk_screen));
#endif

    refreshed = screen_update (screen, FALSE, TRUE, error);

#ifdef HAVE_X11
    gnome_rr_x11_screen_force_timestamp_update (GNOME_RR_X11_SCREEN (screen)); /* this is to keep other clients from thinking that the X server re-detected things by itself - bgo#621046 */
    gdk_x11_display_ungrab (gdk_screen_get_display (screen->priv->gdk_screen));
#endif

    return refreshed;
}
void screen_char7x5(int32_t ch, int32_t row, int32_t col)
{
  int32_t	i;
  // Write a 5x7 character to the display @ row and column
  col = col & 0xf;
  /*
  if (self->displayType == TYPE_128X32) {
    row = row & 0x3;
    for(i = 0; i <= 7; i++) {
      self->buffer[(((row * 128) + (col * 8)) + i)] = ((uint8_t *)(((int32_t)(&(*(uint8_t *)&oleddat[1416])) + (8 * ch)) + i))[0];
    }
  } else
  */
  row = row & 0x7;
  for(i = 0; i <= 7; i++)
  {
    self->buffer[(((row * 128) + (col * 8)) + i)] = ((uint8_t *)(((int32_t)(&(*(uint8_t *)&oleddat[1416])) + (8 * ch)) + i))[0];
  }      
  if (self->AutoUpdate) screen_update();
  self->crsrX = col;
  self->crsrY = row;
}
void power_event(int update_leds)
{
    struct device_state state;

    get_device_state(&state);

    if (state.voltage_level >= POWERUP_VOLTAGE) {
        powerup = 1;
        ALOGD("voltage ok for PU %d\n", state.voltage_level);
    }
    screen_update(state.charge_level,
            state.is_unknown || !state.is_battery_present);
    if (update_leds)
        set_battery_led(&state);

    /* When the charger is unplugged the device shall shutdown at once. */
    if (!shutdown && !state.is_plugged_into_ac && !state.is_plugged_into_usb) {
        shutdown = 1;
        alarm_cancel(screen_brightness_animation_alarm2);
        alarm_cancel(screen_brightness_animation_alarm1);
        screen_brightness_animation_alarm2(NULL);
    }
}
Exemple #15
0
static GdkFilterReturn
screen_on_event (GdkXEvent *xevent,
		 GdkEvent *event,
		 gpointer data)
{
#ifdef HAVE_RANDR
    MateRRScreen *screen = data;
    XEvent *e = xevent;
    int event_num;

    if (!e)
	return GDK_FILTER_CONTINUE;

    event_num = e->type - screen->randr_event_base;

    if (event_num == RRScreenChangeNotify) {
	/* We don't reprobe the hardware; we just fetch the X server's latest
	 * state.  The server already knows the new state of the outputs; that's
	 * why it sent us an event!
	 */
        screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */
#if 0
	/* Enable this code to get a dialog showing the RANDR timestamps, for debugging purposes */
	{
	    GtkWidget *dialog;
	    XRRScreenChangeNotifyEvent *rr_event;
	    static int dialog_num;

	    rr_event = (XRRScreenChangeNotifyEvent *) e;

	    dialog = gtk_message_dialog_new (NULL,
					     0,
					     GTK_MESSAGE_INFO,
					     GTK_BUTTONS_CLOSE,
					     "RRScreenChangeNotify timestamps (%d):\n"
					     "event change: %u\n"
					     "event config: %u\n"
					     "event serial: %lu\n"
					     "----------------------"
					     "screen change: %u\n"
					     "screen config: %u\n",
					     dialog_num++,
					     (guint32) rr_event->timestamp,
					     (guint32) rr_event->config_timestamp,
					     rr_event->serial,
					     (guint32) screen->info->resources->timestamp,
					     (guint32) screen->info->resources->configTimestamp);
	    g_signal_connect (dialog, "response",
			      G_CALLBACK (gtk_widget_destroy), NULL);
	    gtk_widget_show (dialog);
	}
#endif
    }
#if 0
    /* WHY THIS CODE IS DISABLED:
     *
     * Note that in mate_rr_screen_new(), we only select for
     * RRScreenChangeNotifyMask.  We used to select for other values in
     * RR*NotifyMask, but we weren't really doing anything useful with those
     * events.  We only care about "the screens changed in some way or another"
     * for now.
     *
     * If we ever run into a situtation that could benefit from processing more
     * detailed events, we can enable this code again.
     *
     * Note that the X server sends RRScreenChangeNotify in conjunction with the
     * more detailed events from RANDR 1.2 - see xserver/randr/randr.c:TellChanged().
     */
    else if (event_num == RRNotify)
    {
	/* Other RandR events */

	XRRNotifyEvent *event = (XRRNotifyEvent *)e;

	/* Here we can distinguish between RRNotify events supported
	 * since RandR 1.2 such as RRNotify_OutputProperty.  For now, we
	 * don't have anything special to do for particular subevent types, so
	 * we leave this as an empty switch().
	 */
	switch (event->subtype)
	{
	default:
	    break;
	}

	/* No need to reprobe hardware here */
	screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */
    }
#endif

#endif /* HAVE_RANDR */

    /* Pass the event on to GTK+ */
    return GDK_FILTER_CONTINUE;
}
Exemple #16
0
UINT32 prestige_state::screen_update_2bpp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	return screen_update(2, screen, bitmap, cliprect);
}
Exemple #17
0
void screen_clear(void) {
    screen_fill(0);
    screen_update();
}
Exemple #18
0
uint32_t prestige_state::screen_update_1bpp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	return screen_update(1, screen, bitmap, cliprect);
}
Exemple #19
0
static void foogod_repaint_title(void)
{
    screen_erase(&Foogod.titleRect);
    screen_print(&Foogod.titleRect, SP_CENTERED | SP_ONBORDER, "%s", Foogod.title);
    screen_update(&Foogod.titleRect);
}
void text_input(const char *message,int x,int y,char *string,int size)
{
    int sx;
    int a;
    int s=0;
    int i;
    int pos=0;
    static SDL_Surface *save=NULL;
    SDL_Rect clear_rect={16,227,320,16};
    if (!save)
	save=SDL_CreateRGBSurface(SDL_SWSURFACE,320,16,16, 0xF800, 0x7E0,0x1F, 0);

    if (conf.sound) pause_audio(1);

    memset(string,0,size+1);

    SDL_FillRect(buffer,&clear_rect,0);
//    SDL_BlitSurface(buffer,&clear_rect,save,NULL);
    SDL_textout(buffer,x,y,message);
    sx=x+strlen(message)* font_w;
    SDL_EnableUNICODE(1);
    while((a=SDL_getchar())!=-1) {
	if (a==LEFT && pos>0) pos--;
	if (a==RIGHT && pos<s) pos++;
	if (a==BACKSPACE && pos>0) {
	    for(i=pos-1;i<s;i++)
		string[i]=string[i+1];
	    s--;
	    pos--;
	}
	if (a==DEL && pos<s) {
	    for(i=pos;i<s;i++)
		string[i]=string[i+1];
	    s--;
	}
	if (a>32  && s<size ) {
	    for(i=s;i>pos;i--)
		string[i]=string[i-1];
	    string[pos]=(char)a;

	    s++;
	    pos++;
	}
	SDL_FillRect(buffer,&clear_rect,0);
	//SDL_BlitSurface(save,NULL,buffer,&clear_rect);
	SDL_textout(buffer,x,y,message);
	SDL_textout(buffer,sx,y,string);
	/* cursor */
	((Uint16*)buffer->pixels)[352*(16+222)+sx+pos* font_w-1]=0;
	for(i=sx+pos* font_w;i<sx+pos* font_w+ font_w;i++) {
	    ((Uint16*)buffer->pixels)[352*(16+222)+i]=0xFFFF;
	    ((Uint16*)buffer->pixels)[352*(16+221)+i]=0;
	    ((Uint16*)buffer->pixels)[352*(16+223)+i]=0;
	}
	((Uint16*)buffer->pixels)[352*(16+222)+sx+pos* font_w+font_w]=0;	
	screen_update();
    }
    SDL_EnableUNICODE(0);
    if (conf.sound) pause_audio(0);
    reset_frame_skip();
}
Exemple #21
0
void game_loop (GAME *game)
{
    if (!game)
        return;

    ALLEGRO_KEYBOARD_STATE keyboard_state;
    ALLEGRO_EVENT event;
    ALLEGRO_FONT *font = al_load_font ("data/fixed_font.tga", 0, 0);
    SCENE *scene;
    SPRITE_ACTOR *actor;
    LIST_ITEM *item;

    AABB_COLLISIONS collisions;
    aabb_init_collisions (&collisions);

    AABB_COLLISIONS portal_collisions;
    aabb_init_collisions (&portal_collisions);

    AABB_COLLISIONS npc_collisions;
    aabb_init_collisions (&npc_collisions);

    int i = 0;
    bool redraw = true;
    float times[NTIMES] = {0};

    double frame_time, current_time, new_time, mean_frame_time;
    double fixed_dt = 1.0 / FPS, dt;
    double curfps = 0.0;

    current_time = al_get_time ();
    al_start_timer (game->timer);

    float fadeout_duration = 0;
    float fadein_duration = 0;
    SCENE_PORTAL *dest_portal = NULL;

    char *arrow_path = get_resource_path_str ("data/ui/smallarrow_down.png");
    ALLEGRO_BITMAP *sel_arrow = al_load_bitmap (arrow_path);

    while (game->running) {
        scene = game->current_scene;
        actor = game->current_actor;

        if (redraw) {
            al_clear_depth_buffer (0);
            tiled_draw_map_back (scene->map, game->screen.tint,
                                 game->screen.position.x, game->screen.position.y,
                                 game->screen.width, game->screen.height, 0, 0, 0);

            al_draw_textf (font, al_map_rgba_f (0.9, 0, 0, 1), 5, 5, 0, "FPS: %.2f", curfps);

            al_set_render_state (ALLEGRO_ALPHA_TEST, true);
            al_set_render_state (ALLEGRO_DEPTH_TEST, true);
            al_set_render_state (ALLEGRO_DEPTH_FUNCTION, ALLEGRO_RENDER_GREATER);

            al_hold_bitmap_drawing (true);
            sprite_draw (actor, &game->screen);
            item = _al_list_front (scene->npcs);
            while (item) {
                SPRITE_ACTOR *npc_actor = (SPRITE_ACTOR *)_al_list_item_data (item);
                sprite_draw (npc_actor, &game->screen);
                item = _al_list_next (scene->npcs, item);
            }
            al_hold_bitmap_drawing (false);

            al_set_render_state (ALLEGRO_DEPTH_TEST, false);
            al_set_render_state (ALLEGRO_ALPHA_TEST, false);

            if (false) {
                item = _al_list_front (portal_collisions.boxes);
                while (item) {
                    BOX *box = _al_list_item_data (item);
                    box_draw (*box, game->screen.position, al_map_rgb_f (1, 0, 0));
                    item = _al_list_next (portal_collisions.boxes, item);
                }

                aabb_draw (scene->portal_tree, &game->screen, al_map_rgb_f (0, 0, 1));
            }

            tiled_draw_map_fore (scene->map, game->screen.tint,
                                 game->screen.position.x, game->screen.position.y,
                                 game->screen.width, game->screen.height, 0, 0, 0);

            if (game->current_npc) {
                float dx = game->current_npc->actor.box.center.x - game->screen.position.x;
                float dy = game->current_npc->actor.box.center.y - game->screen.position.y;
                dx -= al_get_bitmap_width (sel_arrow) * 0.5f;
                dy -= game->current_npc->actor.box.extent.y * 3.0f;
                al_draw_bitmap (sel_arrow, dx, dy, 0);
            }

            ui_draw (game->ui, &game->screen);
            if (game->force_vsync)
                al_wait_for_vsync ();

            al_flip_display ();
            redraw = false;
        }

        al_wait_for_event (game->event_queue, &event);

        switch (event.type) {
            case ALLEGRO_EVENT_TIMER:
                new_time = al_get_time ();
                frame_time = new_time - current_time;
                current_time = new_time;

                times[i] = frame_time;
                i = (i + 1) % NTIMES;

                mean_frame_time = 0.0;
                for (int j = 0; j < NTIMES; j++)
                    mean_frame_time += times[j];

                mean_frame_time /= NTIMES;
                curfps = 1.0 / mean_frame_time;

                dt = mean_frame_time / fixed_dt;

                if (fadeout_duration > 0.0f) {
                    float fadef = fadeout_duration / TRANS_TIME;
                    game->screen.tint = al_map_rgba_f (fadef, fadef, fadef, 1.0);
                    fadeout_duration -= mean_frame_time;
                    if (fadeout_duration <= 0.0f) {
                        fadein_duration = TRANS_TIME;
                        fadeout_duration = 0.0f;
                        game_enter_portal (game, dest_portal);
                    }
                }

                if (fadein_duration > 0.0f) {
                    float fadef = 1.0 - fadein_duration / TRANS_TIME;
                    game->screen.tint = al_map_rgba_f (fadef, fadef, fadef, 1.0);
                    fadein_duration -= mean_frame_time;
                    if (fadein_duration <= 0.0f) {
                        game->paused = false;
                        fadein_duration = 0.0f;
                    }
                }

                if (game->paused) {
                    redraw = true;
                    break;
                }

                al_get_keyboard_state (&keyboard_state);

                if (al_key_down (&keyboard_state, ALLEGRO_KEY_ESCAPE)) {
                    game->running = false;
                    continue;
                }

                if (al_key_down (&keyboard_state, ALLEGRO_KEY_ENTER)) {
                    ui_show_dialog (game->ui, NULL, NULL);
                }

                if (al_key_down (&keyboard_state, ALLEGRO_KEY_RIGHT)) {
                    actor->event->move_right (actor, dt);
                }
                if (al_key_down (&keyboard_state, ALLEGRO_KEY_LEFT)) {
                    actor->event->move_left (actor, dt);
                }
                if (al_key_down (&keyboard_state, ALLEGRO_KEY_UP)) {
                    actor->event->move_up (actor, dt);
                }
                if (al_key_down (&keyboard_state, ALLEGRO_KEY_DOWN)) {
                    actor->event->move_down (actor, dt);
                }

                BOX box = actor->box;
                box.center.x += actor->movement.x * dt;
                box.center.y += actor->movement.y * dt;

                aabb_collide_fill_cache (scene->collision_tree, &box, &collisions);
                if (scene->collision_tree->num_collisions > 0) {
                    item = _al_list_front (collisions.boxes);
                    while (item) {
                        if (box_lateral (*(BOX *)_al_list_item_data (item), actor->box))
                            actor->movement.x = 0;
                        else
                            actor->movement.y = 0;
                        item = _al_list_next (collisions.boxes, item);
                    }
                }

                aabb_collide_fill_cache (scene->portal_tree, &box, &portal_collisions);
                if (scene->portal_tree->num_collisions > 0) {
                    item = _al_list_front (portal_collisions.boxes);
                    while (item) {
                        BOX *colbox = _al_list_item_data (item);
                        TILED_OBJECT *obj = colbox->data;
                        SCENE_PORTAL *portal = scene_get_portal (game->scenes, obj->name);
                        if (portal && portal->destiny_portal) {
                            dest_portal = scene_get_portal (game->scenes, portal->destiny_portal);
                            if (dest_portal) {
                                fadeout_duration = TRANS_TIME;
                                game->paused = true;
                                actor->movement = (VECTOR2D){0, 0};
                                ui_show_dialog_cstr (game->ui, "Speaker:", "Entering portal.");
                                break;
                            }
                        }
                        item = _al_list_next (portal_collisions.boxes, item);
                    }
                }

                box = screen_box (&game->screen);

                game->current_npc = NULL;
                item = _al_list_front (scene->npcs);
                float max_dist = 0;
                while (item) {
                    SPRITE_NPC *npc = _al_list_item_data (item);
                    float dist = vsqdistance (npc->actor.box.center, game->current_actor->box.center);
                    if (dist < 128.0f * 128.0f && dist > max_dist) {
                        game->current_npc = npc;
                        max_dist = dist;
                    }
                    item = _al_list_next (scene->npcs, item);
                }

                //aabb_collide_fill_cache (scene->npc_tree, &box, &npc_collisions);
                //if (scene->npc_tree->num_collisions > 0) {
                //    item = _al_list_front (npc_collisions.boxes);
                //    float max_dist = 0;
                //    while (item) {
                //        BOX *colbox = _al_list_item_data (item);
                //        SPRITE_NPC *npc = colbox->data;
                //        float dist = vsqdistance (npc->actor.box.center, game->current_actor->box.center);
                //        if (dist < 128.0f * 128.0f && dist > max_dist) {
                //            game->current_npc = npc;
                //            max_dist = dist;
                //        }
                //        item = _al_list_next (npc_collisions.boxes, item);
                //    }
                //}

                screen_update (&game->screen, actor->position, scene->map, dt);
                sprite_update (actor, dt, mean_frame_time);

                item = _al_list_front (scene->npcs);
                while (item) {
                    SPRITE_ACTOR *npc_actor = (SPRITE_ACTOR *)_al_list_item_data (item);
                    sprite_update (npc_actor, dt, mean_frame_time);
                    item = _al_list_next (scene->npcs, item);
                }

                redraw = true;
                break;
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                game->running = false;
                break;
            default:
                fprintf (stderr, "Unsupported event received: %d\n", event.type);
                break;
        }
    }

    aabb_free_collisions (&collisions);
    aabb_free_collisions (&portal_collisions);
    aabb_free_collisions (&npc_collisions);
}
Exemple #22
0
int update()
{
    if (get_active_screen() == NULL)
    {
        return 1;
    }

    timestamp_t current = {0};
    timestamp_set(&current);
    long dt = timestamp_diff(&current, &timer);
    if (dt > 0)
    {
        timer = current;
        screen_update(dt);
    }

    long fps_dt = timestamp_diff(&current, &fps_timer);
    LOGD("DT: %ld", fps_dt);
    if (fps_dt > 500)
    {
        fps = frames * 1000.0f / (float)fps_dt;
        fps_timer = current;
        frames = 0;
        LOGI("FPS: %.2f", fps);
    }
    else
    {
        ++frames;
    }

    char fps_str[32] = {0};
    sprintf(fps_str, "FPS: %.2f", fps);

    const rect_t fps_rect = { 8.0f, 8.0f, 256.0f, 32.0f };
    const rgba_t fps_color = { 1.0f, 0.0f, 0.0f, 0.8f };

    mat4f_t transform = {0};
    mat4_mult(&transform, &camera.proj, &camera.view);

    rect_t screen = { 0, 0, screen_size.x, screen_size.y };

    rgba_t color = {0.7f, 0.7f, 0.0f, 1.0f };

    gfx_set_target(gfx, "test_target", &screen);
    gfx_enable_depth_buffer(gfx, 1);

    gfx_clear(gfx);
    screen_render(gfx, &camera);
    gfx_set_shader(gfx, "text");
    gfx_set_uniform_mat4f(gfx, "uMVP", 1, &transform);
    draw_text(fps_str, &fps_rect, 0.0f, 4.9f, &fps_color);
    gfx_flush(gfx);

    static int take_screenshot = 0;
    if (take_screenshot && frames == 0)
    {
        take_screenshot = 0;

        image_t* img = NULL;
        if (gfx_take_screenshot(gfx, &img) == 0)
        {
            image_save_to_png(img, "screenshot.png");
            image_free(img);
        }
    }

    gfx_set_target(gfx, NULL, &screen);
    gfx_enable_depth_buffer(gfx, 0);
    gfx_clear(gfx);

    int32_t sampler = 0;
    rect_t uv = { 0, screen.height/buffer_size.y, screen.width/buffer_size.x, -screen.height/buffer_size.y };

    gfx_set_shader(gfx, "postprocess");
    gfx_set_uniform_mat4f(gfx, "uMVP", 1, &transform);
    gfx_set_uniform_1i(gfx, "uTex", 1, &sampler);
    gfx_set_texture(gfx, "test_texture", sampler);
    gfx_render_textured_rect(gfx, &screen, 1.0f, &uv);
    gfx_set_texture(gfx, NULL, sampler);

    gfx_flush(gfx);

    return 0;
}
Exemple #23
0
void render() {
  scene_draw(scene, &bmp);
  screen_update(display, &bmp);
}
Exemple #24
0
static void update_gngeo_gui(SDL_Surface *desk) {
    SDL_BlitSurface(desk,&desk_rect,buffer,&buf_rect);
    screen_update();
}
Exemple #25
0
int 
main (int argc, char **argv)
{
	int ch;
	/*char uptimeInfo[15], lightInfo[15], timebuf[15];*/
	/*int lightlevel;*/
	int ocontrast = 40; /* Contrast defaults to 40 */
	screen_t *sc;
	sensor_t  sensors;
	led_t	  displed;
	extern char *optarg;
	extern int optind;/*, opterr, optopt;*/


	while ((ch = getopt(argc, argv, "lDvc:")) != -1) {
		switch (ch) {
			case 'l':
				led_on_darkness=1;
				break;
			case 'D':
				dodaemon=1;
				break;
			case 'v':
				verbose_mode=1;
				break;
			case 'c':
				ocontrast = atoi(optarg);
				break;
			default:
				usage();
		}
	}
	argc -= optind;
	argv += optind;
	if (dodaemon) {
		daemon(1, 0);
	}
	openlog("pcd8544", LOG_PID|LOG_PERROR, LOG_LOCAL0);
	/* print infos */
	syslog(LOG_LOCAL0|LOG_INFO, "pilab");

  


	if ((sc = screen_init(DIN_PIN, SCLK_PIN, DC_PIN, RST_PIN, CS_PIN, ocontrast)) == NULL) {
		syslog(LOG_LOCAL0|LOG_INFO, "failed to init screen");
		err(3, "failed to init screen");
	}

	/* check wiringPi setup */
	delay(2000);
 	if (verbose_mode)
		syslog(LOG_LOCAL0|LOG_DEBUG, "initialisation of screen led");
        led_init(&displed, DISP_LED_GPIO);
 	if (verbose_mode)
		syslog(LOG_LOCAL0|LOG_DEBUG, "initialisation of screen led - bringing up");
	led_setstate(&displed, LED_UP);
  
	for (;;) {
		/* clear lcd */
		LCDclear();
	  
		if (sensors_read(&sensors) < 0)
			syslog(LOG_LOCAL0|LOG_INFO, "failed to read data from sensors");
		if (led_on_darkness) {
			if (sensors.sens_light < 50 && displed.l_state != LED_UP) {
				if (verbose_mode)
					syslog(LOG_LOCAL0|LOG_DEBUG, "bringing screen led up");
				led_setstate(&displed, LED_UP);
			} else if (sensors.sens_light > 50 && displed.l_state == LED_UP)
				led_setstate(&displed, LED_DOWN);
		}

		if (statistics_update(sc, &sensors) < 0)
			syslog(LOG_LOCAL0|LOG_INFO, "failed to update statistics");
		if (screen_include(sc) < 0)
			syslog(LOG_LOCAL0|LOG_INFO, "failed to include file line");
		/* build screen */
		screen_update(sc);
	  
		sleep(5);
	}
  return 0;
}
Exemple #26
0
int main(int argc, char** argv)
{
	int i;
	int window = 1;
	int showhelp = 0;
	int fps = 0;
	int width = 640;
	int height = 360;
	int fullscreen = 0;

	if(argc > 2) {
		for(i = 2; i < argc; i++) {
			char* dup = strdup(argv[i]);
			char* tok = strtok(dup, "=");			

			if(strcmp(argv[i], "-s") == 0) {
				stepping = 1;
			}else if(strcmp(argv[i], "-noscreen") == 0) {
				window = 0;
			}else if(strcmp(argv[i], "-h") == 0) {
				showhelp = 1;
			}else if(strcmp(argv[i], "-fps") == 0) {
				fps = 1;
			}else if(strcmp(tok, "-width") == 0) {
				tok = strtok(NULL, "=");
				width = strtol(tok, NULL, 0);
			}else if(strcmp(tok, "-height") == 0) {
				tok = strtok(NULL, "=");
				height = strtol(tok, NULL, 0);
			}else if(strcmp(argv[i], "-f") == 0) {
				fullscreen = 1;
			}
			else {
				printf("Ignoring unknown argument '%s'. Use '-h' for more information\n", argv[i]);
			}
		}
	}

	if(argc < 2 | showhelp) {
		printf("Usage: ccpu <binary> [options]\n\nOptions:\n\t-s - Stepping mode\n\t-noscreen - No screen/window\n\t-fps - Output fps\n\t-width=w - Set window width\n\t-height=h - Set window height\n\t-f - Fullscreen mode\n");
		return -1;
	}

	FILE* f = fopen(argv[1], "rb");
	if(f == NULL) {
		printf("Failed to open '%s'\n", argv[1]);
		return -1;
	}
	fseek(f, 0, SEEK_END);
	int length = ftell(f);
	rewind(f);
	u8* buffer = (u8*)malloc(sizeof(u8)*length);
	int read = fread(buffer, sizeof(u8), length, f);
	fclose(f);

	if(read != length) {
		printf("Failed to read file '%s'\n", argv[1]);
		return -1;
	}

	f = fopen("rom.bin", "rb");
	if(f == NULL) {
		printf("Could not open 'rom.bin'\n");
		return -1;
	}
	fseek(f, 0, SEEK_END);
	int rom_length = ftell(f);
	if(rom_length > 0x1000) {
		printf("'rom.bin' is %04X bytes long, but can not be longer than 0x100 bytes\n", rom_length);
		return -1;
	}
	rewind(f);
	u8* rom_buffer = (u8*)malloc(sizeof(u8)*rom_length);
	read = fread(rom_buffer, sizeof(u8), rom_length, f);
	if(read != rom_length) {
		printf("Failed to read 'rom.bin'\n");
		return -1;
	}
	fclose(f);

	c = cpu_init(0x1000);

	for(i = 0; i < length; i++) {
		c->mem[c->ip+i] = buffer[i];
	}

	for(i = 0; i < rom_length; i++) {
		c->mem[0xF000+i] = rom_buffer[i];
	}

	c->ip = 0xF000;

	SDL_Thread* ccpu_thread = SDL_CreateThread(cpu_thread_func, "ccpu_thread", NULL);
	
	if(window) {
	Screen* s = screen_init(width, height, 640, 360, 8, 12, 16, 16, fullscreen);

	Uint32 now = SDL_GetTicks();
	Uint32 lastTime = now;
	Uint32 fpsCounterTime = now;
	Uint32 interval = 16;

	int frames = 0;

	while(!screen_closerequested(s)) {
		now = SDL_GetTicks();
		
		if(now - lastTime > interval) {
			screen_update(s, c);
			frames++;
			lastTime = now;	
		}

		if(now - fpsCounterTime > 1000) {
			if(fps) printf("fps %d\n", frames);
			frames = 0;
			fpsCounterTime = now;
		}

		screen_pollevents(s, c);
		if(!cpu_running) break;
	}
	screen_cleanup(s);
	SDL_DetachThread(ccpu_thread);
	}else {
		SDL_WaitThread(ccpu_thread, NULL);
	}
	
	return 0;
}