// Runs into main thread static int particles_draw_last(lua_State *L) { if (!pdls_head) return 0; while (pdls_head) { particle_draw_last *pdl = pdls_head; particles_draw(pdl->ps, pdl->x, pdl->y, pdl->zoom); pdls_head = pdls_head->next; free(pdl); } return 0; }
// Runs into main thread static int particles_to_screen(lua_State *L) { particles_type *ps = (particles_type*)auxiliar_checkclass(L, "core{particles}", 1); float x = luaL_checknumber(L, 2); float y = luaL_checknumber(L, 3); bool show = lua_toboolean(L, 4); float zoom = lua_isnumber(L, 5) ? lua_tonumber(L, 5) : 1; if (!show || !ps->init) return 0; if (!ps->texture) return 0; if (ps->fboalter) { particle_draw_last *pdl = malloc(sizeof(particle_draw_last)); pdl->ps = ps; pdl->x = x; pdl->y = y; pdl->zoom = zoom; pdl->next = pdls_head; pdls_head = pdl; return 0; } particles_draw(ps, x, y, zoom); if (ps->sub) { ps = ps->sub; if (ps->fboalter) { particle_draw_last *pdl = malloc(sizeof(particle_draw_last)); pdl->ps = ps; pdl->x = x; pdl->y = y; pdl->zoom = zoom; pdl->next = pdls_head; pdls_head = pdl; } else particles_draw(ps, x, y, zoom); } return 0; }
bool dgreed_render(void) { particles_draw(); return malka_states_step(); }
int dgreed_main(int argc, const char** argv) { log_init("pview.log", LOG_LEVEL_INFO); video_init(800, 600, "PView"); rand_init(666); GuiDesc style = greed_gui_style(false); gui_init(&style); particles_init("greed_assets/", 5); TexHandle empty = tex_load("greed_assets/empty.png"); if(psystem_descs_count < 1) LOG_ERROR("No particle systems described!"); int active_backg = 0; int active_desc = 0; const char* active_desc_name = psystem_descs[active_desc].name; RectF gui_area = rectf(0.0f, 0.0f, 520.0f, 80.0f); RectF gui_area2 = rectf(0.0f, 500.0f, 280.0f, 600.0f); Vector2 button_prev_pos = vec2(10.0f, 10.0f); Vector2 button_next_pos = vec2(280.0f, 10.0f); Vector2 button_backg_pos = vec2(10.0f, 550.0f); Vector2 label_name_pos = vec2(20.0f, 60.0f); char label_text[256]; while(system_update()) { RectF src = rectf_null(); RectF dest = {0.0f, 0.0f, EDITOR_WIDTH, EDITOR_HEIGHT}; Color c = backgrounds[active_backg % ARRAY_SIZE(backgrounds)]; video_draw_rect(empty, 0, &src, &dest, c); if(mouse_down(MBTN_LEFT)) { uint x, y; mouse_pos(&x, &y); Vector2 pos = vec2((float)x, (float)y); if(!rectf_contains_point(&gui_area, &pos)) if(!rectf_contains_point(&gui_area2, &pos)) particles_spawn(active_desc_name, &pos, 0.0f); } particles_update(time_ms() / 1000.0f); sprintf(label_text, "Current psystem: %s", active_desc_name); gui_label(&label_name_pos, label_text); if(gui_button(&button_prev_pos, "Previuos")) active_desc = MAX(0, active_desc-1); if(gui_button(&button_next_pos, "Next")) active_desc = MIN(psystem_descs_count-1, active_desc+1); if(gui_button(&button_backg_pos, "Background color")) active_backg++; active_desc_name = psystem_descs[active_desc].name; particles_draw(); draw_grid(0, 12.0f); video_present(); } tex_free(empty); particles_close(); gui_close(); greed_gui_free(); video_close(); log_close(); return 0; }
int game_loop(){ unsigned redraw = 0; game_rect t; rect_Zero(&t); sprite_sheet = gamespr_create("ski1.bmp"); animation_init(); init_player(); start_new_game(0); while(!mainloop){ ALLEGRO_EVENT e; ALLEGRO_TIMEOUT timeout; int i; al_init_timeout(&timeout, 0.06); bool late = al_wait_for_event_until(g_queue, &e, &timeout); if(late){ switch(e.type){ case ALLEGRO_EVENT_DISPLAY_CLOSE: mainloop = 1; break; case ALLEGRO_EVENT_KEY_UP: player_poll_kbd_up(&e); break; case ALLEGRO_EVENT_KEY_DOWN: player_poll_kbd_dn(&e); break; case ALLEGRO_EVENT_TIMER: /* main clock updates 1/60ms (60FPS LOCK) */ if(e.timer.source == g_timer){ particle_list = particles_clean(particle_list, 0); particles_update(particle_list); player_update_screen(); player_update(&ski_player, &playfield); for(i = 1; i < MAX_SPRITES; i++){ update_enemy(i); } update_enemy_behavior(gobj_list, &playfield); redraw = 1; } /* update for the chronomenter run every 100ms only) */ if( e.timer.source == timer_chrono){ HUD_UpdateChrono(); DMSG("%d", al_get_timer_count(timer_chrono)); } break; } if( redraw == 1 && al_event_queue_is_empty(g_queue)){ redraw = 0; al_clear_to_color(WHITE_COLOR); particles_draw(NULL, particle_list); player_draw(ski_player.object->position.x, ski_player.object->position.y ); for(i = 1; i < MAX_OBJECTS; i++){ int enemy_type = gobj_list[i].type; draw_enemy(enemy_type, i, 0,0, gobj_list[i].position.x, gobj_list[i].position.y, 32,32); } HUD_create_stats_box(); al_flip_display(); } } } HUD_destroy(); unload_spritesheets(); window_deinit(); particle_list = particles_clean(particle_list, PARTICLES_ALL_CLEAN); return EXIT_SUCCESS; }