示例#1
0
/**
 * \brief Updates the program state.
 * \param self Program.
 * \return Nonzero if the program is still running.
 */
int limai_program_update (
	LIMaiProgram* self)
{
	int i;
	float secs;

	/* Calculate time delta. */
	self->curr_tick = lisys_timeval_init ();
	secs = lisys_timeval_get_diff (self->prev_tick, self->curr_tick);
	self->prev_tick = self->curr_tick;

	/* Frames per second. */
	self->ticks[self->ticki++] = secs;
	if (self->ticki == LIMAI_PROGRAM_FPS_TICKS)
		self->ticki = 0;
	self->tick = 0.0f;
	for (i = 0 ; i < LIMAI_PROGRAM_FPS_TICKS ; i++)
		self->tick += self->ticks[i];
	self->fps = LIMAI_PROGRAM_FPS_TICKS / self->tick;
	self->tick = self->tick / LIMAI_PROGRAM_FPS_TICKS;

	/* Update subsystems. */
	lical_callbacks_update (self->callbacks);
	lical_callbacks_call (self->callbacks, "tick", lical_marshal_DATA_FLT, secs);

	/* Sleep until end of frame. */
	if (self->sleep > (int)(1000000 * secs))
		lisys_usleep (self->sleep - (int)(1000000 * secs));

	return !self->quit;
}
示例#2
0
static void Model_changed (LIScrArgs* args)
{
	LIMaiProgram* program;

	/* Invoke callbacks. */
	program = liscr_script_get_userdata (args->script, LISCR_SCRIPT_PROGRAM);
	lical_callbacks_call (program->callbacks, "model-changed", lical_marshal_DATA_PTR, args->self);
}
示例#3
0
static void private_model_removed (
	void*       data,
	LIMdlModel* model)
{
	LIMaiProgram* self = data;

	/* Invoke callbacks. */
	lical_callbacks_call (self->callbacks, "model-free", lical_marshal_DATA_PTR, model);
}
void LIPhyMotionState::setWorldTransform (
	const btTransform& transform)
{
	this->current = transform;
	if (this->object->control != NULL)
	{
		this->previous = this->current;
		this->object->control->update ();
		lical_callbacks_call (this->object->physics->callbacks, "physics-transform", lical_marshal_DATA_PTR, this->object);
	}
}
示例#5
0
static int private_resize (
	LICliWindow* self,
	int          width,
	int          height,
	int          fullscreen,
	int          sync)
{
	int i;
	Uint32 flags;
	SDL_Rect* best = NULL;
	SDL_Rect** modes;

	/* Determine screen surface flags. */
	if (fullscreen)
	{
		flags = SDL_OPENGL | SDL_FULLSCREEN;
		modes = SDL_ListModes (NULL, flags);
		if (modes != NULL && modes != (SDL_Rect**) -1)
		{
			/* Determine the best possible fullscreen mode. */
			for (i = 0 ; modes[i] ; i++)
			{
				if (best == NULL ||
				   (LIMAT_ABS (modes[i]->w - width) < LIMAT_ABS (best->w - width) &&
				    LIMAT_ABS (modes[i]->h - height) < LIMAT_ABS (best->h - height)))
					best = modes[i];
			}
		}
		if (best != NULL)
		{
			/* Set the resolution to the best mode found. */
			width = best->w;
			height = best->h;
		}
		else
		{
			/* Revert to windowed mode if no fullscreen modes. */
			flags = SDL_OPENGL | SDL_RESIZABLE;
			fullscreen = 0;
		}
	}
	else
		flags = SDL_OPENGL | SDL_RESIZABLE;

	/* Unload all graphics. */
	/* Since changing the video mode erases the OpenGL context in Windows,
	   we have to unload all textures, shaders, vertex buffers, etc. */
#ifdef WIN32
	if (self->client->render != NULL)
		lical_callbacks_call (self->client->program->callbacks, "context-lost", lical_marshal_DATA_INT, 0);
#endif

	/* Recreate surface. */
	/* This destroys all graphics data in Windows. */
	SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 0);
	if (sync)
		SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1);
	SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
	self->screen = SDL_SetVideoMode (width, height, 0, flags);
	if (self->screen == NULL)
	{
		lisys_error_set (LISYS_ERROR_UNKNOWN, "cannot set video mode");
		return 0;
	}

	/* Initialize libraries. */
	if (!livid_video_init ())
		return 0;

	/* Store mode. */
	self->mode.width = width;
	self->mode.height = height;
	self->mode.fullscreen = fullscreen;
	self->mode.vsync = sync;

	/* Reload all graphics. */
	/* Since changing the video mode erases the OpenGL context in Windows,
	   we have to reload all textures, shaders, vertex buffers, etc. */
#ifdef WIN32
	if (self->client->render != NULL)
		lical_callbacks_call (self->client->program->callbacks, "context-lost", lical_marshal_DATA_INT, 1);
#endif

	return 1;
}
示例#6
0
/**
 * \brief Frees the program.
 *
 * \param self Program.
 */
void limai_program_free (
	LIMaiProgram* self)
{
	int i;
	LIMaiExtension* extension;
	LIMaiExtension* extension_next;
	LIMaiEvent* event;
	LIMaiEvent* event_next;
	LIMaiMessage* message;
	LIMaiMessage* message_next;

	/* Invoke callbacks. */
	if (self->callbacks != NULL)
		lical_callbacks_call (self->callbacks, "program-shutdown", lical_marshal_DATA);

	/* Free script. */
	if (self->script != NULL)
		liscr_script_free (self->script);

	/* Free extensions. */
	if (self->extensions != NULL)
	{
		for (extension = self->extensions ; extension != NULL ; extension = extension_next)
		{
			extension_next = extension->next;
			((void (*)(void*)) extension->info->free) (extension->object);
			if (extension->module != NULL)
				lisys_module_free (extension->module);
			lisys_free (extension);
		}
	}

	/* Free components. */
	if (self->components != NULL)
	{
		lisys_assert (self->components->size == 0);
		lialg_strdic_free (self->components);
	}

	/* Free the model manager. */
	if (self->models != NULL)
		limdl_manager_free (self->models);

	/* Invoke callbacks. */
	if (self->callbacks != NULL)
		lical_callbacks_call (self->callbacks, "program-free", lical_marshal_DATA);

	/* Free callbacks. */
	if (self->callbacks != NULL)
	{
		lical_handle_releasev (self->calls, sizeof (self->calls) / sizeof (LICalHandle));
		lical_callbacks_free (self->callbacks);
	}

	if (self->paths != NULL)
		lipth_paths_free (self->paths);

	/* Free messaging. */
	if (self->message_mutex != NULL)
		lisys_mutex_free (self->message_mutex);
	for (i = 0 ; i < LIMAI_MESSAGE_QUEUE_MAX ; i++)
	{
		for (message = self->messages[i] ; message != NULL ; message = message_next)
		{
			message_next = message->next;
			limai_message_free (message);
		}
	}

	/* Free events. */
	for (event = self->events_first ; event != NULL ; event = event_next)
	{
		event_next = event->next;
		limai_event_free (event);
	}

	lisys_free (self->launch_args);
	lisys_free (self->launch_name);
	lisys_free (self->args);
	lisys_free (self);
}