void free_sound(void) { sound_manager* sound_manager_handle = global_get(global_get_singleton(), GLOBAL_SOUND_MANAGER); sound_map* sound_map_handle = global_get(global_get_singleton(), GLOBAL_SOUND_MAP); sound_manager_free(&sound_manager_handle); sound_map_free(&sound_map_handle); }
void af_window_set_height(int height) { if (height < 0) return ; global_set("height", (gpointer)height); GtkWidget *window = global_get("window"); if (gtk_window_get_resizable(GTK_WINDOW(window))) { gtk_window_resize(GTK_WINDOW(window), (gint)global_get("width"), (gint)global_get("height")); } else { gtk_widget_set_size_request(GTK_WIDGET(window), (gint)global_get("width"), (gint)global_get("height")); } }
void free_systems(void) { syscontainer* syscontainer_handle = global_get(global_get_singleton(), GLOBAL_SYSCONTAINER); syscontainer_free(&syscontainer_handle); entity_global* entity_global_handle = global_get(global_get_singleton(), GLOBAL_ENTITY_GLOBAL); entity_global_free(&entity_global_handle); collision_solver* collision_solver_handle = global_get(global_get_singleton(), GLOBAL_COLLISION_SOLVER); collision_solver_free(&collision_solver_handle); entity_map* entity_map_handle = global_get(global_get_singleton(), GLOBAL_ENTITY_MAP); entity_map_free(&entity_map_handle); }
void af_window_set_title(char *title) { GtkWidget *window = global_get("window"); global_set("title", title); gtk_window_set_title(GTK_WINDOW(window), title); }
void af_window_set_position(int x, int y) { GtkWidget *window = global_get("window"); global_set("x", (gpointer)x); global_set("y", (gpointer)y); gtk_window_move(GTK_WINDOW(window), x, y); }
int af_window_get_top() { GtkWidget *window = global_get("window"); int x, y; gtk_window_get_position(GTK_WINDOW(window), &x, &y); return y; }
gboolean af_window_restore() { if (!af_window_get_visible()) return FALSE; GtkWidget *window = global_get("window"); switch(af_window_get_state()){ case GDK_WINDOW_STATE_WITHDRAWN: af_window_set_visible(TRUE); break; case GDK_WINDOW_STATE_ICONIFIED: gtk_window_deiconify(GTK_WINDOW(window)); break; case GDK_WINDOW_STATE_MAXIMIZED: gtk_window_unmaximize(GTK_WINDOW(window)); break; case GDK_WINDOW_STATE_STICKY: gtk_window_unstick(GTK_WINDOW(window)); break; case GDK_WINDOW_STATE_FULLSCREEN: af_window_set_fullscreen(FALSE); break; case GDK_WINDOW_STATE_ABOVE: af_window_set_above(FALSE); break; case GDK_WINDOW_STATE_BELOW: af_window_set_below(FALSE); break; default: return FALSE; } return TRUE; }
int framebuffer_alloc(framebuffer** target, unsigned int width, unsigned int height) { if (!target) { debug_critical("[framebuffer_alloc] target cannot be NULL"); return 0; } if (*target) { debug_warning("[framebuffer_alloc] target points to non NULL handle, possible memory leak"); } if (!width && !height) { width = window_get_width(global_get(global_get_singleton(), GLOBAL_WINDOW)); height = window_get_height(global_get(global_get_singleton(), GLOBAL_WINDOW)); } framebuffer* output = h_malloc(sizeof(framebuffer)); glGenFramebuffers(1, &output->fb); glBindFramebuffer(GL_FRAMEBUFFER, output->fb); glGenTextures(1, &output->texture); glBindTexture(GL_TEXTURE_2D, output->texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glGenRenderbuffers(1, &output->renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, output->renderbuffer); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, output->renderbuffer); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, output->texture, 0); GLenum buffers[] = {GL_COLOR_ATTACHMENT0}; glDrawBuffers(1, buffers); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { debug_critical("[framebuffer_alloc] failed to create framebuffer"); return 0; } *target = output; return 1; }
gboolean af_window_minimize() { if (!af_window_get_visible()) return FALSE; GtkWidget *window = global_get("window"); gtk_window_iconify(GTK_WINDOW(window)); return TRUE; }
UgResult ug_plugin_global_get (const UgPluginInterface* iface, guint parameter, gpointer data) { UgGlobalGetFunc global_get = iface->global_get; if (global_get) return global_get (parameter, data); return UG_RESULT_UNSUPPORT; }
void af_window_set_left(int left) { GtkWidget *window = global_get("window"); int x, y; gtk_window_get_position(GTK_WINDOW(window), &x, &y); x = left; global_set("x", (gpointer)x); gtk_window_move(GTK_WINDOW(window), x, y); }
void af_window_set_top(int top) { GtkWidget *window = global_get("window"); int x, y; gtk_window_get_position(GTK_WINDOW(window), &x, &y); y = top; global_set("y", (gpointer)y); gtk_window_move(GTK_WINDOW(window), x, y); }
void af_window_set_fullscreen(gboolean fullscreen) { GtkWidget *window = global_get("window"); global_set("fullscreen", (gpointer)fullscreen); if (fullscreen) gtk_window_fullscreen(GTK_WINDOW(window)); else gtk_window_unfullscreen(GTK_WINDOW(window)); }
int af_window_get_height() { int width, height; GtkWidget *window = global_get("window"); if (gtk_window_get_resizable(GTK_WINDOW(window))) { gtk_window_get_size(GTK_WINDOW(window), &width, &height); } else { gtk_widget_get_size_request(window, &width, &height); } return height; }
void system_gameobject_draw(unsigned int event_id, entity* target_entity) { if (event_id == 0) { /* only activate for draw event */ /* here we will query the entity components and then draw the entity. */ component_position* entity_position = entity_get_component(target_entity, component_position_type); component_gameobject* entity_gameobject = entity_get_component(target_entity, component_gameobject_type); component_primitive* entity_primitive = entity_get_component(target_entity, component_primitive_type); component_texture* entity_texture = entity_get_component(target_entity, component_texture_type); global* global_handle = global_get_singleton(); window* window_handle = global_get(global_handle, GLOBAL_WINDOW); hl_render* hl_render_handle = global_get(global_handle, GLOBAL_HL_RENDER); float current_time = time_get_elapsed(window_handle); if ((current_time - entity_texture->time_point) * 1000.0f >= entity_texture->interval[entity_texture->current_animation]) { entity_texture->time_point = current_time; entity_texture->current_frame++; /* Add loop-around! */ if (entity_texture->current_frame >= entity_texture->frame_count[entity_texture->current_animation]) { entity_texture->current_frame = 0; } } texture* current_texture = entity_texture->texture_buffer[entity_texture->current_animation][entity_texture->current_frame]; hl_render_batch render_batch; render_batch.x = entity_position->x; render_batch.y = entity_position->y; render_batch.angle = entity_position->angle; render_batch.z = entity_gameobject->layer; render_batch.render_prim = entity_primitive->primitive_handle; render_batch.render_texture = current_texture; hl_render_add_batch(hl_render_handle, &render_batch); } }
void system_entity_global(unsigned int event_id, entity* entity_handle) { switch (event_id) { case EVENT_PRE_LOGIC: { /* If the entity global component value is not the special undef. value ("__undef__") we set the index in entity_global. */ component_global* component_global_handle = entity_get_component(entity_handle, component_global_type); if (strcmp(component_global_handle->id, "__undef__") && !component_global_handle->set) { entity* global_entity_handle = entity_global_get(global_get(global_get_singleton(), GLOBAL_ENTITY_GLOBAL), component_global_handle->id); if (global_entity_handle) { debug_warning("[system_entity_global] collision between entity %X and %X, fighting for [%s]", entity_handle, global_entity_handle, component_global_handle->id); } debug_message("[system_entity_global] set global id [%s] to %x", component_global_handle->id, entity_handle); entity_global_set(global_get(global_get_singleton(), GLOBAL_ENTITY_GLOBAL), component_global_handle->id, entity_handle); component_global_handle->set = 1; } } break; } }
void free_graphic(void) { window* window_handle = global_get(global_get_singleton(), GLOBAL_WINDOW); hl_render* hl_render_handle = global_get(global_get_singleton(), GLOBAL_HL_RENDER); camera* camera_handle = global_get(global_get_singleton(), GLOBAL_CAMERA); input* input_handle = global_get(global_get_singleton(), GLOBAL_INPUT); shader* shader_texture_handle = global_get(global_get_singleton(), GLOBAL_SHADER_TEXTURE); text* text_handle = global_get(global_get_singleton(), GLOBAL_TEXT); debug_draw* debug_draw_handle = global_get(global_get_singleton(), GLOBAL_DEBUG_DRAW); window_free(&window_handle); hl_render_free(&hl_render_handle); camera_free(&camera_handle); input_free(&input_handle); shader_free(&shader_texture_handle); text_free(&text_handle); debug_draw_free(&debug_draw_handle); }
void* alloc_component_music_trigger(char* buffer, int buffer_size) { if (!buffer) { debug_critical("[alloc_component_music_trigger] buffer cannot be NULL"); return NULL; } component_music_trigger* output = h_malloc(sizeof(component_music_trigger)); if (!output) { debug_critical("[alloc_component_music_trigger] memory allocation failure"); return NULL; } memset(output, 0, sizeof(component_music_trigger)); sound_map* sound_map_handle = global_get(global_get_singleton(), GLOBAL_SOUND_MAP); output->target_sound = sound_map_get(sound_map_handle, buffer); memcpy(output->original_sound, buffer, ((buffer_size > 255) ? 255 : buffer_size)); return output; }
static void do_put (SoupServer *server, SoupMessage *msg, const char *path) { struct stat st; FILE *f; gboolean created = TRUE; static char *path2 = NULL; if (!path2){g_free(path2); path2=NULL;} path2 = g_build_filename((const gchar *)global_get("htmlhome"), path, NULL); if (stat (path2, &st) != -1) { const char *match = soup_message_headers_get_one (msg->request_headers, "If-None-Match"); if (match && !strcmp (match, "*")) { soup_message_set_status (msg, SOUP_STATUS_CONFLICT); return; } if (!S_ISREG (st.st_mode)) { soup_message_set_status (msg, SOUP_STATUS_FORBIDDEN); return; } created = FALSE; } f = fopen (path2, "w"); if (!f) { soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR); return; } fwrite (msg->request_body->data, 1, msg->request_body->length, f); fclose (f); soup_message_set_status (msg, created ? SOUP_STATUS_CREATED : SOUP_STATUS_OK); }
void component_music_trigger_set_param(void* handle, unsigned int index, char* value) { if (!handle) { debug_warning("[component_music_trigger_set_param] handle cannot be NULL"); return; } component_music_trigger* this = (component_music_trigger*) handle; sound_map* sound_map_handle = global_get(global_get_singleton(), GLOBAL_SOUND_MAP); switch (index) { case COMPONENT_MUSIC_TRIGGER_INDEX_TRACKNAME: { this->target_sound = sound_map_get(sound_map_handle, value); if (!this->target_sound) { debug_warning("[component_music_trigger_set_param] no sound located at index %s", value); } else { snprintf(this->original_sound, COMPONENT_MUSIC_TRIGGER_STORE_LENGTH, "%s", value); } } break; } }
gboolean af_window_get_resizable() { GtkWidget *window = global_get("window"); return gtk_window_get_resizable(GTK_WINDOW(window)); }
void af_window_set_resizable(gboolean resizable) { GtkWidget *window = global_get("window"); global_set("resizable", (gpointer)resizable); gtk_window_set_resizable(GTK_WINDOW(window), resizable); }
void af_window_set_visible(gboolean visible) { GtkWidget *window = global_get("window"); gtk_widget_set_visible(window, visible); }
int main(int argc, char** argv) { init_core(); debug_message("[hunter] initialized core"); init_graphic(); debug_message("[hunter] initialized graphics, mode W%d H%d", window_get_width(global_get(global_get_singleton(), GLOBAL_WINDOW)), window_get_height(global_get(global_get_singleton(), GLOBAL_WINDOW))); init_sound(); debug_message("[hunter] initialized sound"); init_systems(); debug_message("[hunter] initialized systems"); window* window_handle = global_get(global_get_singleton(), GLOBAL_WINDOW); input* input_handle = global_get(global_get_singleton(), GLOBAL_INPUT); syscontainer* syscontainer_handle = global_get(global_get_singleton(), GLOBAL_SYSCONTAINER); text* text_handle = global_get(global_get_singleton(), GLOBAL_TEXT); hl_render* hl_render_handle = global_get(global_get_singleton(), GLOBAL_HL_RENDER); shader* shader_texture_handle = global_get(global_get_singleton(), GLOBAL_SHADER_TEXTURE); camera* camera_handle = global_get(global_get_singleton(), GLOBAL_CAMERA); debug_draw* debug_draw_handle = global_get(global_get_singleton(), GLOBAL_DEBUG_DRAW); float delta_ref_point = time_get_elapsed(window_handle); float delta_accumulator = 0.0f; float delta_frame_time = 0.0f; float fps_accumulator = 0.0f; float fps_value = 0.0f; float fps_value_last = fps_value; unsigned int fps_counter = 0; unsigned int game_kill_flag = 0; debug_message("[hunter] posting init event to systems"); syscontainer_post_event(syscontainer_handle, EVENT_INIT); while (!game_kill_flag) { delta_frame_time = time_get_elapsed(window_handle) - delta_ref_point; delta_ref_point = time_get_elapsed(window_handle); window_update(window_handle); input_state current_input_state; input_get_input_state(input_handle, ¤t_input_state); game_kill_flag |= window_get_should_close(window_handle); game_kill_flag |= current_input_state.key_dev; window_set_clear_color(window_handle, 1.0f, 0.0f, 1.0f, 0.0f); debug_draw_clear(debug_draw_handle); window_clear(window_handle); delta_accumulator += delta_frame_time; if (delta_accumulator < 0.0f) { delta_accumulator = 0.0f; } while (delta_accumulator >= 1.0f / DELTA_REFERENCE_FPS) { syscontainer_post_event(syscontainer_handle, EVENT_PRE_LOGIC); syscontainer_post_event(syscontainer_handle, EVENT_LOGIC); syscontainer_post_event(syscontainer_handle, EVENT_POST_LOGIC); delta_accumulator -= 1.0f / DELTA_REFERENCE_FPS; } syscontainer_post_event(syscontainer_handle, EVENT_DRAW); window_set_blend_mode(window_handle, WINDOW_BLEND_ALPHA); debug_draw_render_all(debug_draw_handle); hl_render_draw(hl_render_handle, shader_texture_handle, camera_handle); hl_render_clear(hl_render_handle); fps_counter++; fps_accumulator += delta_frame_time; if (fps_accumulator >= 1.0f) { fps_value_last = fps_value; fps_value = (float) fps_counter / fps_accumulator; fps_counter = 0; fps_accumulator = 0.0f; } text_batch fps_batch = {20, 20, 0.2f, 0.8f, 1.0f, 1.0f, "", "monospace", 12}; sprintf(fps_batch.text_data, "FPS : %3.2f (%3.2f)", fps_value, fps_value - fps_value_last); text_submit_batch(text_handle, &fps_batch); text_render_all(text_handle); text_flush_batch(text_handle); window_swap_buffers(window_handle); } debug_message("[hunter] posting destroy event to systems"); syscontainer_post_event(syscontainer_handle, EVENT_DESTROY); free_systems(); free_sound(); free_graphic(); free_core(); h_free_all(); debug_message("[hunter] terminated cleanly"); return 0; }
void af_window_set_border(gboolean border) { GtkWidget *window = global_get("window"); global_set("border", (gpointer)border); gtk_window_set_decorated(GTK_WINDOW(window), border); }
gboolean af_window_get_border() { GtkWidget *window = global_get("window"); return gtk_window_get_decorated(GTK_WINDOW(window)); }
void af_window_set_below(gboolean below) { GtkWidget *window = global_get("window"); gtk_window_set_keep_below(GTK_WINDOW(window), below); }
void af_window_set_above(gboolean above) { GtkWidget *window = global_get("window"); gtk_window_set_keep_above(GTK_WINDOW(window), above); }
static int init_setting(GtkWidget * window, GtkWidget * view) { gint root_x, root_y; gint screen_width, screen_height; /* Setting Window */ gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_window_set_title(GTK_WINDOW(window), global_get("title")); gtk_widget_set_size_request(GTK_WIDGET(window), 10, 10); gtk_window_set_resizable(GTK_WINDOW(window), (gboolean)global_get("resizeable")); gtk_window_set_decorated(GTK_WINDOW(window), (gboolean)global_get("border")); if (gtk_window_get_resizable(GTK_WINDOW(window))) { gtk_window_resize(GTK_WINDOW(window), (gint)global_get("width"), (gint)global_get("height")); } else { gtk_widget_set_size_request(GTK_WIDGET(window), (gint)global_get("width"), (gint)global_get("height")); } /* Move Window */ screen_get_size(&screen_width, &screen_height); root_x = (screen_width - (gint)global_get("width")) / 2; root_y = (screen_height - (gint)global_get("height")) / 2; if ((gint)global_get("x") != 10000) root_x = (gint)global_get("x"); if ((gint)global_get("y") != 10000) root_y = (gint)global_get("y"); if (root_x < 0) root_x = screen_width + root_x; if (root_y < 0) root_y = screen_height + root_y; gtk_window_move(GTK_WINDOW(window), root_x, root_y); /* Setting Icon */ if (g_file_test(global_get("icon"), G_FILE_TEST_EXISTS)) { gtk_window_set_icon_from_file(GTK_WINDOW(window), global_get("icon"), NULL); } /* Fullscreen */ if ((gboolean)global_get("fullscreen")) af_window_set_fullscreen(TRUE); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(af_exit), NULL); g_signal_connect(G_OBJECT(window), "window-state-event", G_CALLBACK(window_onstatechange), NULL); /* Setting Webkit */ WebKitWebSettings *setting = webkit_web_view_get_settings (WEBKIT_WEB_VIEW(view)); g_object_set(G_OBJECT(setting), "default-encoding", global_get("encode"), NULL); g_object_set(G_OBJECT(setting), "enable-webgl", TRUE, NULL); //g_object_set(G_OBJECT(view), "self-scrolling", TRUE, NULL); g_object_set(G_OBJECT(setting), "default-font-family", "SimSun", NULL); g_object_set(G_OBJECT(setting), "monospace-font-family", "SimSun", NULL); g_object_set(G_OBJECT(setting), "sans-serif-font-family", "SimSun", NULL); g_object_set(G_OBJECT(setting), "serif-font-family", "SimSun", NULL); g_object_set(G_OBJECT(setting), "cursive-font-family", "SimSun", NULL); webkit_web_view_set_settings(WEBKIT_WEB_VIEW(view), setting); g_signal_connect(WEBKIT_WEB_VIEW(view), "window-object-cleared", G_CALLBACK(js_callback), NULL); g_signal_connect(WEBKIT_WEB_VIEW(view), "close-web-view", G_CALLBACK(webview_onclose), NULL); return 0; }
gboolean af_window_get_active() { GtkWidget *window = global_get("window"); return gtk_window_is_active(GTK_WINDOW(window)); }