void ScriptController::loadScript(const char* path, bool forceReload)
{
    GP_ASSERT(path);
    std::set<std::string>::iterator iter = _loadedScripts.find(path);
    if (iter == _loadedScripts.end() || forceReload)
    {
#ifdef __ANDROID__
        const char* scriptContents = FileSystem::readAll(path);
        if (luaL_dostring(_lua, scriptContents))
        {
            GP_WARN("Failed to run Lua script with error: '%s'.", lua_tostring(_lua, -1));
        }
        SAFE_DELETE_ARRAY(scriptContents);
#else
        std::string fullPath;
        if (!FileSystem::isAbsolutePath(path))
        {
            fullPath.append(FileSystem::getResourcePath());
        }
        fullPath.append(path);
        if (luaL_dofile(_lua, fullPath.c_str()))
        {
            GP_WARN("Failed to run Lua script with error: '%s'.", lua_tostring(_lua, -1));
        }
#endif
        if (iter == _loadedScripts.end())
        {
            _loadedScripts.insert(path);
        }
    }
}
Exemple #2
0
void printProperties(Properties* properties, unsigned int tabCount)
{
    // Print the name and ID of the current namespace.
    const char* spacename = properties->getNamespace();
    const char* id = properties->getId();
    std::string tabs;
    for (unsigned int i = 0; i < tabCount; i++)
    {
        tabs.append("\t");
    }
    GP_WARN("\n%s%s %s\n%s{", tabs.c_str(), spacename, id, tabs.c_str());
 
    // Print all properties in this namespace.
    const char* name = properties->getNextProperty();
    const char* value = NULL;
    while (name != NULL)
    {
        value = properties->getString(name);
        GP_WARN("%s\t%s = %s", tabs.c_str(), name, value);
        name = properties->getNextProperty();
    }
 
    // Print the properties of every namespace within this one.
    Properties* space = properties->getNextNamespace();
    while (space != NULL)
    {
        printProperties(space, tabCount+1);
        space = properties->getNextNamespace();
    }

    GP_WARN("%s}", tabs.c_str());
}
Exemple #3
0
void Mode::gestureEvent(Gesture::GestureEvent evt, int x, int y, ...)
{
    if(app->hasOverlay()) return;
    va_list arguments;
    va_start(arguments, y);
    switch(evt) {
        case Gesture::GESTURE_TAP: {
            if(isSelecting()) {
                MyNode *node = getTouchNode();
                Vector3 point = getTouchPoint();
                if(node) {
                    node->updateTransform();
                    node->setBase();
                }
                setSelectedNode(node, point);
                if(node) GP_WARN("selected %s at %s", node->getId(), app->pv(point).c_str());
            }
            break;
        }
        case Gesture::GESTURE_LONG_TAP:
            break;
        case Gesture::GESTURE_PINCH: {
            float scale = (float) va_arg(arguments, double);
            if(app->_navMode >= 0) {
                float baseRadius = _cameraStateBase->radius;
                app->setCameraZoom(fminf(300.0f, fmaxf(3.0f, baseRadius / fmaxf(scale, 0.01f))));
            }
            break;
        }
        case Gesture::GESTURE_DRAG: {
            if(app->_navMode >= 0) {
                Vector2 touch = getTouchPix(), delta(x - touch.x, y - touch.y);
                float radius = _cameraStateBase->radius, theta = _cameraStateBase->theta, phi = _cameraStateBase->phi;
                GP_WARN("drag delta %f, %f", delta.x, delta.y);
                GP_WARN("camera from %f, %f, %f", radius, theta, phi);
                float deltaPhi = delta.y * M_PI / 400.0f, deltaTheta = delta.x * M_PI / 400.0f;
                phi = fmin(89.9f * M_PI/180, fmax(-89.9f * M_PI/180, phi + deltaPhi));
                theta += deltaTheta;
                GP_WARN("to %f, %f, %f", radius, theta, phi);
                app->setCameraEye(radius, theta, phi);
            }
            break;
        }
        case Gesture::GESTURE_DROP: {
            break;
        }
        case Gesture::GESTURE_ROTATE: {
            float rotation = (float) va_arg(arguments, double), velocity = (float) va_arg(arguments, double);
            if(app->_navMode >= 0) {
                float theta = _cameraStateBase->theta;
                app->setCameraTheta(theta - rotation);
            }
            break;
        }
        default: break;
    }
    va_end(arguments);
}
Exemple #4
0
Stream* FileSystem::open(const char* path, size_t streamMode, bool external)
{
    bool useExternal = (streamMode & WRITE) != 0 || external;
    char modeStr[] = "rb";
    if ((streamMode & WRITE) != 0)
        modeStr[0] = 'w';
#ifdef __ANDROID__
    std::string fullPath(__resourcePath);
    fullPath += resolvePath(path);

    if (useExternal)
    {
        // Open a file on the SD card
        size_t index = fullPath.rfind('/');
        if (index != std::string::npos)
        {
            std::string directoryPath = fullPath.substr(0, index);
            gp_stat_struct s;
            if (stat(directoryPath.c_str(), &s) != 0)
                makepath(directoryPath, 0777);
        }
        return FileStream::create(fullPath.c_str(), modeStr);
    }
    else
    {
        // First try the SD card
        Stream* stream = FileStream::create(fullPath.c_str(), modeStr);

        if (!stream)
        {
            // Otherwise fall-back to assets loaded via the AssetManager
            fullPath = __assetPath;
            fullPath += resolvePath(path);

            stream = FileStreamAndroid::create(fullPath.c_str(), modeStr);
        }

        return stream;
    }
#else
    std::string fullPath;
    getFullPath(path, fullPath, useExternal);
    if(useExternal && __externalPath.compare(__resourcePath) != 0) {
        size_t index = fullPath.rfind('/');
        if(index != std::string::npos) {
            std::string directoryPath = fullPath.substr(0, index);
            gp_stat_struct s;
            if(stat(directoryPath.c_str(), &s) != 0)
                makepath(directoryPath, 0777);
        }
    }
    GP_WARN("Opening file %s", fullPath.c_str());
    if(useExternal) GP_WARN("External file");
    FileStream* stream = FileStream::create(fullPath.c_str(), modeStr);
    return stream;
#endif
}
Exemple #5
0
/* Seek to the current position */
static void seek_cur_pos(struct zip_priv *priv)
{
	unsigned int cur_table = priv->cur_pos / ZIP_CHUNKS_IN_TABLE;
	unsigned int cur_pos;

	if (priv->cur_table_pos != cur_table) {
		unsigned int i;

		GP_DEBUG(3, "cur_pos %u out of cur table %u",
		         priv->cur_pos, priv->cur_table_pos);

		priv->cur_table = &priv->table;

		for (i = 0; i < cur_table; i++) {
			if (priv->cur_table->next)
				priv->cur_table = priv->cur_table->next;
			else
				GP_WARN("The cur_pos points after last table");
		}

		priv->cur_table_pos = cur_table;
	}

	//TODO: Asert that we are not in last table and cur_pos < table_used

	cur_pos = priv->cur_pos % ZIP_CHUNKS_IN_TABLE;

	GP_DEBUG(2, "Setting current position to %u (%li)",
	         priv->cur_pos, priv->cur_table->offsets[cur_pos]);

	gp_io_seek(priv->io, priv->cur_table->offsets[cur_pos], GP_IO_SEEK_SET);
}
Exemple #6
0
static int parse_fb_params(char *params, int *flags, const char **fb)
{
    char *param;

    if (!params)
        return 0;

    do {
        param = params;
        params = next_param(params);

        if (!strcasecmp(param, "no_shadow")) {
            *flags &= ~GP_FB_SHADOW;
            GP_DEBUG(1, "Shadow framebuffer disabled");
            continue;
        }

        if (!strcasecmp(param, "new_console")) {
            *flags |= GP_FB_ALLOC_CON;
            GP_DEBUG(1, "Console allocation enabled");
            continue;
        }

        *fb = param;

        if (strncmp(*fb, "/dev/", 5))
            GP_WARN("Console dev set to '%s', are you sure?", *fb);

        GP_DEBUG(1, "Framebuffer console set to '%s'", *fb);

    } while (params);

    return 0;
}
Exemple #7
0
gp_pixmap *gp_filter_resize_alloc(const gp_pixmap *src,
                                  gp_size w, gp_size h,
                                  gp_interpolation_type type,
                                  gp_progress_cb *callback)
{
	gp_pixmap *res;

	if (!w && !h) {
		GP_WARN("Invalid result size 0x0!");
		errno = EINVAL;
		return NULL;
	}

	if (!w)
		w = (h * src->w + src->h/2) / src->h;

	if (!h)
		h = (w * src->h + src->w/2) / src->w;

	res = gp_pixmap_alloc(w, h, src->pixel_type);
	if (!res)
		return NULL;

	if (resize(src, res, type, callback)) {
		gp_pixmap_free(res);
		return NULL;
	}

	return res;
}
Exemple #8
0
static int zip_seek(gp_container *self, int offset,
                    enum gp_container_whence whence)
{
	struct zip_priv *priv = GP_CONTAINER_PRIV(self);
	unsigned int where;
	int ret;

	GP_DEBUG(1, "Seek offset=%i whence=%i", offset, whence);

	switch (whence) {
	case GP_CONT_CUR:
		if (offset < 0 && priv->cur_pos < (unsigned int)-offset) {
			GP_WARN("Current position %u offset %i",
			        priv->cur_pos, offset);
			where = 0;
		} else {
			where = priv->cur_pos + offset;
		}
	break;
	case GP_CONT_FIRST:
		where = offset;
	break;
	default:
		return ENOSYS;
	}

	ret = set_cur_pos(priv, where);

	self->cur_img = priv->cur_pos;

	return ret;
}
Exemple #9
0
void MaterialParameter::bind(Effect* effect)
{
    GP_ASSERT(effect);

    // If we had a Uniform cached that is not from the passed in effect,
    // we need to update our uniform to point to the new effect's uniform.
    if (!_uniform || _uniform->getEffect() != effect)
    {
        _uniform = effect->getUniform(_name.c_str());

        if (!_uniform)
        {
            // This parameter was not found in the specified effect, so do nothing.
            GP_WARN("Warning: Material parameter '%s' not found in effect '%s'.", _name.c_str(), effect->getId());
            return;
        }
    }

    switch (_type)
    {
    case MaterialParameter::FLOAT:
        effect->setValue(_uniform, _value.floatValue);
        break;
    case MaterialParameter::FLOAT_ARRAY:
        effect->setValue(_uniform, _value.floatPtrValue, _count);
        break;
    case MaterialParameter::INT:
        effect->setValue(_uniform, _value.intValue);
        break;
    case MaterialParameter::INT_ARRAY:
        effect->setValue(_uniform, _value.intPtrValue, _count);
        break;
    case MaterialParameter::VECTOR2:
        effect->setValue(_uniform, reinterpret_cast<Vector2*>(_value.floatPtrValue), _count);
        break;
    case MaterialParameter::VECTOR3:
        effect->setValue(_uniform, reinterpret_cast<Vector3*>(_value.floatPtrValue), _count);
        break;
    case MaterialParameter::VECTOR4:
        effect->setValue(_uniform, reinterpret_cast<Vector4*>(_value.floatPtrValue), _count);
        break;
    case MaterialParameter::MATRIX:
        effect->setValue(_uniform, reinterpret_cast<Matrix*>(_value.floatPtrValue), _count);
        break;
    case MaterialParameter::SAMPLER:
        effect->setValue(_uniform, _value.samplerValue);
        break;
    case MaterialParameter::SAMPLER_ARRAY:
        effect->setValue(_uniform, _value.samplerArrayValue, _count);
        break;
    case MaterialParameter::METHOD:
        GP_ASSERT(_value.method);
        _value.method->setValue(effect);
        break;
    default:
        GP_ERROR("Unsupported material parameter type (%d).", _type);
        break;
    }
}
Exemple #10
0
Text* Text::create(Properties* properties)
{
    // Check if the Properties is valid and has a valid namespace.
    if (!properties || strcmp(properties->getNamespace(), "text") != 0)
    {
        GP_ERROR("Properties object must be non-null and have namespace equal to 'text'.");
        return NULL;
    }

    // Get font path.
    const char* fontPath = properties->getString("font");
    if (fontPath == NULL || strlen(fontPath) == 0)
    {
        GP_ERROR("Text is missing required font file path.");
        return NULL;
    }

    // Get text
    const char* text = properties->getString("text");
    if (text == NULL || strlen(text) == 0)
    {
        GP_ERROR("Text is missing required 'text' value.");
        return NULL;
    }

    // Get size
    int size = properties->getInt("size"); // Default return is 0 if a value doesn't exist
    if (size < 0)
    {
        GP_WARN("Text size must be a positive value, with zero being default font size. Using default font size.");
        size = 0;
    }

    // Get text color
    kmVec4 color = { 1.0f, 1.0f ,1.0f, 1.0f };
    if (properties->exists("color"))
    {
        switch (properties->getType("color"))
        {
        case Properties::VECTOR3:
            color.w = 1.0f;
            properties->getVector3("color", (kmVec3*)&color);
            break;
        case Properties::VECTOR4:
            properties->getVector4("color", &color);
            break;
        case Properties::STRING:
        default:
            properties->getColor("color", &color);
            break;
        }
    }

    // Create
    return Text::create(fontPath, text, color, size);
}
Exemple #11
0
static int parse_x11_params(char *params, GP_Size *w, GP_Size *h,
                            enum GP_BackendX11Flags *flags)
{
    char *param;

    if (!params)
        return 0;

    do {
        param = params;
        params = next_param(params);

        if (!strcasecmp(param, "use_root")) {
            *flags |= GP_X11_USE_ROOT_WIN;
            GP_DEBUG(1, "X11: Using root window");
            continue;
        }

        if (!strcasecmp(param, "create_root")) {
            *flags |= GP_X11_CREATE_ROOT_WIN;
            GP_DEBUG(1, "X11: Creating root window");
            continue;
        }

        if (!strcasecmp(param, "disable_shm")) {
            *flags |= GP_X11_DISABLE_SHM;
            GP_DEBUG(1, "X11: Disabling SHM");
            continue;
        }

        if (!strcasecmp(param, "fs")) {
            *flags |= GP_X11_FULLSCREEN;
            GP_DEBUG(1, "X11: Enabling fullscreen");
            continue;
        }

        /*
         * Accepts only string with format "intxint" or "intXint"
         */
        int sw, sh;
        unsigned int n;

        if (sscanf(param, "%i%*[xX]%i%n", &sw, &sh, &n) == 2 && n == strlen(param)) {
            *w = sw;
            *h = sh;
            continue;
        }

        GP_WARN("X11: Invalid parameters '%s'", param);
        errno = EINVAL;
        return 1;
    } while (params);

    return 0;
}
Exemple #12
0
static void free_console(struct fb_priv *fb)
{
	/* restore blinking cursor */
	if (ioctl(fb->con_fd, KDSETMODE, KD_TEXT))
		GP_WARN("Failed to ioctl KDSETMODE (restore KDMODE)");

	/* switch back console */
	if (fb->last_con_nr != -1)
		ioctl(fb->con_fd, VT_ACTIVATE, fb->last_con_nr);

	close(fb->con_fd);
}
Exemple #13
0
int gp_filter_resize(const gp_pixmap *src, gp_pixmap *dst,
                     gp_interpolation_type type,
                     gp_progress_cb *callback)
{
	if (src->pixel_type != dst->pixel_type) {
		GP_WARN("The src and dst pixel types must match");
		errno = EINVAL;
		return 1;
	}

	return resize(src, dst, type, callback);
}
Exemple #14
0
int gp_io_writef(gp_io *io, uint16_t *types, ...)
{
	va_list va;
	uint8_t *ptr, t;
	int32_t i4;
	int16_t i2;

	va_start(va, types);

	while (*types != GP_IO_END) {
		switch (TYPE(*types)) {
		case GP_IO_CONST:
			t = VAL(*types);
			if (gp_io_write(io, &t, 1) != 1)
				goto err;
		break;
		case GP_IO_L2:
		case GP_IO_B2:
			i2 = va_arg(va, int);
			ptr = (void*)&i2;

			if (needs_swap(*types))
				GP_SWAP(ptr[0], ptr[1]);

			if (gp_io_write(io, ptr, 2) != 2)
				goto err;
		break;
		case GP_IO_L4:
		case GP_IO_B4:
			i4 = va_arg(va, int);
			ptr = (void*)&i4;

			if (needs_swap(*types)) {
				GP_SWAP(ptr[0], ptr[3]);
				GP_SWAP(ptr[1], ptr[2]);
			}

			if (gp_io_write(io, ptr, 4) != 4)
				goto err;
		break;
		default:
			GP_WARN("Invalid type %"PRIu16"\n", *types);
			goto err;
		}
		types++;
	}

	va_end(va);
	return 0;
err:
	va_end(va);
	return -1;
}
Exemple #15
0
float PhysicsRigidBody::getHeight(float x, float z) const
{
    GP_ASSERT(_collisionShape);
    GP_ASSERT(_node);

    // If our node has a terrain, call getHeight() on it since we need to factor in local
    // scaling on the terrain into the height calculation.
    Terrain* terrain = dynamic_cast<Terrain*>(_node->getDrawable());
    if (terrain)
        return terrain->getHeight(x, z);

    // This function is only supported for heightfield rigid bodies.
    if (_collisionShape->getType() != PhysicsCollisionShape::SHAPE_HEIGHTFIELD)
    {
        GP_WARN("Attempting to get the height of a non-heightfield rigid body.");
        return 0.0f;
    }

    GP_ASSERT(_collisionShape->_shapeData.heightfieldData);

    // Ensure inverse kmMat4 is updated so we can transform from world back into local heightfield coordinates for indexing
    if (_collisionShape->_shapeData.heightfieldData->inverseIsDirty)
    {
        _collisionShape->_shapeData.heightfieldData->inverseIsDirty = false;

        //_node->getWorldMatrix().invert(&_collisionShape->_shapeData.heightfieldData->inverse);
		kmMat4Invert(&_collisionShape->_shapeData.heightfieldData->inverse, &_node->getWorldMatrix());
    }

    // Calculate the correct x, z position relative to the heightfield data.
    float cols = _collisionShape->_shapeData.heightfieldData->heightfield->getColumnCount();
    float rows = _collisionShape->_shapeData.heightfieldData->heightfield->getRowCount();

    GP_ASSERT(cols > 0);
    GP_ASSERT(rows > 0);

    //kmVec3 v = _collisionShape->_shapeData.heightfieldData->inverse * Vector3(x, 0.0f, z);
	kmVec3 v = vec3Zero;
	kmMat3Transform(&v, &_collisionShape->_shapeData.heightfieldData->inverse, x, 0.0f, z, 0.0f);
	x = v.x + (cols - 1) * 0.5f;
    z = v.z + (rows - 1) * 0.5f;

    // Get the unscaled height value from the HeightField
    float height = _collisionShape->_shapeData.heightfieldData->heightfield->getHeight(x, z);

    // Apply scale back to height
    kmVec3 worldScale = vec3Zero;
    //_node->getWorldMatrix().getScale(&worldScale);
	kmMat4Decompose(&_node->getWorldMatrix(), &worldScale, NULL, NULL);
    height *= worldScale.y;

    return height;
}
Exemple #16
0
void ScriptController::registerCallback(const char* callback, const char* function)
{
    ScriptCallback scb = toCallback(callback);
    if (scb < INVALID_CALLBACK)
    {
        _callbacks[scb].push_back(function);
    }
    else
    {
        GP_WARN("Invalid script callback function specified: %s", callback);
    }
}
void ParticleEmitter::setTexture(const char* texturePath, BlendMode blendMode)
{
    Texture* texture = Texture::create(texturePath, true);
    if (texture)
    {
        setTexture(texture, blendMode);
        texture->release();
    }
    else
    {
        GP_WARN("Failed set new texture on particle emitter: %s", texturePath);
    }
}
Exemple #18
0
static off_t sub_seek(gp_io *io, off_t off, enum gp_io_whence whence)
{
	struct sub_io *sub_io = GP_IO_PRIV(io);
	off_t io_size, ret, poff;

	switch (whence) {
	case GP_IO_SEEK_CUR:
		//TODO: Overflow
		poff = sub_io->cur + off;

		if (poff < sub_io->start || poff > sub_io->end) {
			errno = EINVAL;
			return -1;
		}

		ret = gp_io_seek(sub_io->io, off, whence);
	break;
	case GP_IO_SEEK_SET:
		io_size = sub_io->end - sub_io->start;

		if (off > io_size || off < 0) {
			errno = EINVAL;
			return -1;
		}

		ret = gp_io_seek(sub_io->io, sub_io->start + off, whence);
	break;
	case GP_IO_SEEK_END:
		io_size = sub_io->end - sub_io->start;

		if (off + io_size < 0 || off > 0) {
			errno = EINVAL;
			return -1;
		}

		ret = gp_io_seek(sub_io->io, sub_io->end + off, GP_IO_SEEK_SET);
	break;
	default:
		GP_WARN("Invalid whence");
		errno = EINVAL;
		return -1;
	}

	if (ret == -1)
		return -1;

	sub_io->cur = ret;

	return sub_io->cur - sub_io->start;
}
Exemple #19
0
int gp_io_mark(gp_io *self, enum gp_io_mark_types type)
{
	off_t ret;

	switch (type) {
	case GP_IO_MARK:
		ret = gp_io_seek(self, 0, GP_IO_SEEK_CUR);
	break;
	case GP_IO_REWIND:
		ret = gp_io_seek(self, self->mark, SEEK_SET);
	break;
	default:
		GP_WARN("Invalid mark type");
		return -1;
	}

	if (ret == -1) {
		GP_WARN("Failed to seek I/O Stream");
		return -1;
	}

	self->mark = ret;
	return 0;
}
void ScriptController::loadScript(const char* path, bool forceReload)
{
    std::set<std::string>::iterator iter = _loadedScripts.find(path);
    if (iter == _loadedScripts.end() || forceReload)
    {
        const char* scriptContents = FileSystem::readAll(path);
        if (luaL_dostring(_lua, scriptContents))
            GP_WARN("Failed to run Lua script with error: '%s'.", lua_tostring(_lua, -1));

        SAFE_DELETE_ARRAY(scriptContents);

        if (iter == _loadedScripts.end())
            _loadedScripts.insert(path);
    }
}
Exemple #21
0
void ScriptController::unregisterCallback(const char* callback, const char* function)
{
    ScriptCallback scb = toCallback(callback);
    if (scb < INVALID_CALLBACK)
    {
        std::vector<std::string>& list = _callbacks[scb];
        std::vector<std::string>::iterator itr = std::find(list.begin(), list.end(), std::string(function));
        if (itr != list.end())
            list.erase(itr);
    }
    else
    {
        GP_WARN("Invalid script callback function specified: %s", callback);
    }
}
Exemple #22
0
/*
 * Restore console and keyboard mode to whatever was there before.
 */
static void exit_kbd(struct fb_priv *fb)
{
	if (ioctl(fb->con_fd, KDSKBMODE, fb->saved_kb_mode) < 0) {
		GP_DEBUG(1, "Failed to ioctl KDSKBMODE (restore KBMODE)"
		         " /dev/tty%i: %s", fb->con_nr,
	         strerror(errno));
	}

	if (fb->restore_termios) {
		if (tcsetattr(fb->con_fd, TCSANOW, &fb->ts) < 0) {
			GP_WARN("Failed to tcsetattr() (restore termios): %s",
			        strerror(errno));
		}
	}
}
Exemple #23
0
static boolean fill_input_buffer(struct jpeg_decompress_struct *cinfo)
{
	int ret;
	struct my_source_mgr* src = (void*)cinfo->src;

	ret = GP_IORead(src->io, src->buffer, src->size);

	if (ret <= 0) {
		GP_WARN("Failed to fill buffer, IORead returned %i", ret);
		return FALSE;
	}

	src->mgr.next_input_byte = src->buffer;
	src->mgr.bytes_in_buffer = ret;
	return TRUE;
}
Exemple #24
0
static off_t file_seek(gp_io *self, off_t off, enum gp_io_whence whence)
{
	struct file_io *file_io = GP_IO_PRIV(self);

	switch (whence) {
	case GP_IO_SEEK_SET:
	case GP_IO_SEEK_CUR:
	case GP_IO_SEEK_END:
	break;
	default:
		GP_WARN("Invalid whence");
		errno = EINVAL;
		return -1;
	}

	return lseek(file_io->fd, off, whence);
}
Exemple #25
0
Gamepad::ButtonMapping Gamepad::getButtonMappingFromString(const char* string)
{
    if (strcmp(string, "A") == 0 || strcmp(string, "BUTTON_A") == 0)
        return BUTTON_A;
    else if (strcmp(string, "B") == 0 || strcmp(string, "BUTTON_B") == 0)
        return BUTTON_B;
    else if (strcmp(string, "C") == 0 || strcmp(string, "BUTTON_C") == 0)
        return BUTTON_C;
    else if (strcmp(string, "X") == 0 || strcmp(string, "BUTTON_X") == 0)
        return BUTTON_X;
    else if (strcmp(string, "Y") == 0 || strcmp(string, "BUTTON_Y") == 0)
        return BUTTON_Y;
    else if (strcmp(string, "Z") == 0 || strcmp(string, "BUTTON_Z") == 0)
        return BUTTON_Z;
    else if (strcmp(string, "MENU1") == 0 || strcmp(string, "BUTTON_MENU1") == 0)
        return BUTTON_MENU1;
    else if (strcmp(string, "MENU2") == 0 || strcmp(string, "BUTTON_MENU2") == 0)
        return BUTTON_MENU2;
    else if (strcmp(string, "MENU3") == 0 || strcmp(string, "BUTTON_MENU3") == 0)
        return BUTTON_MENU3;
    else if (strcmp(string, "MENU4") == 0 || strcmp(string, "BUTTON_MENU4") == 0)
        return BUTTON_MENU4;
    else if (strcmp(string, "L1") == 0 || strcmp(string, "BUTTON_L1") == 0)
        return BUTTON_L1;
    else if (strcmp(string, "L2") == 0 || strcmp(string, "BUTTON_L2") == 0)
        return BUTTON_L2;
    else if (strcmp(string, "L3") == 0 || strcmp(string, "BUTTON_L3") == 0)
        return BUTTON_L3;
    else if (strcmp(string, "R1") == 0 || strcmp(string, "BUTTON_R1") == 0)
        return BUTTON_R1;
    else if (strcmp(string, "R2") == 0 || strcmp(string, "BUTTON_R2") == 0)
        return BUTTON_R2;
    else if (strcmp(string, "R3") == 0 || strcmp(string, "BUTTON_R3") == 0)
        return BUTTON_R3;
    else if (strcmp(string, "UP") == 0 || strcmp(string, "BUTTON_UP") == 0)
        return BUTTON_UP;
    else if (strcmp(string, "DOWN") == 0 || strcmp(string, "BUTTON_DOWN") == 0)
        return BUTTON_DOWN;
    else if (strcmp(string, "LEFT") == 0 || strcmp(string, "BUTTON_LEFT") == 0)
        return BUTTON_LEFT;
    else if (strcmp(string, "RIGHT") == 0 || strcmp(string, "BUTTON_RIGHT") == 0)
        return BUTTON_RIGHT;

    GP_WARN("Unknown GamepadButton string.");
    return BUTTON_A;
}
Vector3 PhysicsConstraint::getWorldCenterOfMass(const Node* node)
{
    GP_ASSERT(node);

    const BoundingSphere& sphere = node->getBoundingSphere();
    if (!(sphere.center.isZero() && sphere.radius == 0))
    {
        // The world-space center of mass is the sphere's center.
        return sphere.center;
    }

    // Warn the user that the node has no bounding volume.
    GP_WARN("Node %s' has no bounding volume - center of mass is defaulting to local coordinate origin.", node->getId());

    Vector3 center;
    node->getWorldMatrix().transformPoint(&center);
    return center;
}
Exemple #27
0
static void read_jpg_metadata(struct jpeg_decompress_struct *cinfo,
                              GP_DataStorage *storage)
{
	jpeg_saved_marker_ptr marker;

	GP_DataStorageAddInt(storage, NULL, "Width", cinfo->image_width);
	GP_DataStorageAddInt(storage, NULL, "Height", cinfo->image_height);
	GP_DataStorageAddInt(storage, NULL, "Channels", cinfo->num_components);
	GP_DataStorageAddString(storage, NULL, "Color Space",
	                     get_colorspace(cinfo->out_color_space));

	for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
		switch (marker->marker) {
		case JPEG_COM: {
			//TODO: Is comment NULL terminated?
			char buf[marker->data_length+1];

			GP_DEBUG(3, "JPEG_COM comment block, size %u",
			         (unsigned int)marker->data_length);

			memcpy(buf, marker->data, marker->data_length);
			buf[marker->data_length] = '\0';
			GP_DataStorageAddString(storage, NULL, "Comment", buf);
			//GP_MetaDataCreateString(data, "comment", (void*)marker->data,
			//                        marker->data_length, 1);
		} break;
		case JPEG_APP0:
			GP_TODO("JFIF");
		break;
		case JPEG_APP0 + 1: {
			GP_IO *io = GP_IOMem(marker->data, marker->data_length, NULL);
			if (!io) {
				GP_WARN("Failed to create MemIO");
				return;
			}
			GP_ReadExif(io, storage);
			GP_IOClose(io);
		} break;
		}
	}
}
Exemple #28
0
/*
 * Save console mode and set the mode to raw.
 */
static int init_kbd(struct fb_priv *fb)
{
	struct termios t;
	int fd = fb->con_fd;

	if (tcgetattr(fd, &fb->ts)) {
		GP_WARN("Failed to tcgetattr(): %s", strerror(errno));
		fb->restore_termios = 0;
	} else {
		fb->restore_termios = 1;
	}

	cfmakeraw(&t);

	if (tcsetattr(fd, TCSANOW, &t) < 0) {
		GP_DEBUG(1, "Failed to tcsetattr(): %s",
		         strerror(errno));
		close(fd);
		return -1;
	}

	if (ioctl(fd, KDGKBMODE, &fb->saved_kb_mode)) {
		GP_DEBUG(1, "Failed to ioctl KDGKBMODE tty%i: %s",
		         fb->con_nr, strerror(errno));
		close(fd);
		return -1;
	}

	GP_DEBUG(2, "Previous keyboard mode was '%i'",
	         fb->saved_kb_mode);

	if (ioctl(fd, KDSKBMODE, K_MEDIUMRAW) < 0) {
		GP_DEBUG(1, "Failed to ioctl KDSKBMODE tty%i: %s",
		        fb->con_nr, strerror(errno));
		close(fd);
		return -1;
	}

	return 0;
}
Exemple #29
0
static int resize(const gp_pixmap *src, gp_pixmap *dst,
                  gp_interpolation_type type,
                  gp_progress_cb *callback)
{
	switch (type) {
	case GP_INTERP_NN:
		return gp_filter_resize_nn(src, dst, callback);
	case GP_INTERP_LINEAR_INT:
		return gp_filter_resize_linear_int(src, dst, callback);
	case GP_INTERP_LINEAR_LF_INT:
		return gp_filter_resize_linear_lf_int(src, dst, callback);
	case GP_INTERP_CUBIC:
		return gp_filter_resize_cubic(src, dst, callback);
	case GP_INTERP_CUBIC_INT:
		return gp_filter_resize_cubic_int(src, dst, callback);
	}

	GP_WARN("Invalid interpolation type %u", (unsigned int)type);

	errno = EINVAL;
	return 1;
}
int lua_Uniform_getType(lua_State* state)
{
    // Get the number of parameters.
    int paramCount = lua_gettop(state);

    // Attempt to match the parameters to a valid binding.
    switch (paramCount)
    {
        case 1:
        {
            if ((lua_type(state, 1) == LUA_TUSERDATA))
            {
                Uniform* instance = getInstance(state);
                GLenum result = instance->getType();

                // Push the return value onto the stack.
                GP_WARN("Attempting to return value with unrecognized type GLenum as an unsigned integer.");
                lua_pushunsigned(state, result);

                return 1;
            }
            else
            {
                lua_pushstring(state, "lua_Uniform_getType - Failed to match the given parameters to a valid function signature.");
                lua_error(state);
            }
            break;
        }
        default:
        {
            lua_pushstring(state, "Invalid number of parameters (expected 1).");
            lua_error(state);
            break;
        }
    }
    return 0;
}