Ejemplo n.º 1
0
static void append(VGPath path, int numSegments, const VGubyte* segments, int numCoordinates, const VGfloat* coordinates)
{
	MK_ASSERT(numCoordinates <= 26);
	
	VGPathDatatype datatype = (VGPathDatatype)vgGetParameteri(path, VG_PATH_DATATYPE);
	VGfloat scale = vgGetParameterf(path, VG_PATH_SCALE);
	VGfloat bias = vgGetParameterf(path, VG_PATH_BIAS);
	
	switch(datatype)
	{
		case VG_PATH_DATATYPE_S_8:
		{
			
			int8_t data[26];
			for(int i=0;i<numCoordinates;i++)
				data[i] = (int8_t)floor((coordinates[i] - bias) / scale + 0.5f);	//add 0.5 for correct rounding
			vgAppendPathData(path, numSegments, segments, data);
			break;
		}
			
		case VG_PATH_DATATYPE_S_16:
		{
			
			int16_t data[26];
			for(int i=0;i<numCoordinates;i++)
				data[i] = (int16_t)floor((coordinates[i] - bias) / scale + 0.5f);	//add 0.5 for correct rounding
			vgAppendPathData(path, numSegments, segments, data);
			break;
		}
			
		case VG_PATH_DATATYPE_S_32:
		{
			int32_t data[26];
			for(int i=0;i<numCoordinates;i++)
				data[i] = (int32_t)floor((coordinates[i] - bias) / scale + 0.5f);	//add 0.5 for correct rounding
			vgAppendPathData(path, numSegments, segments, data);
			break;
		}
			
		default:
		{
			MK_ASSERT(datatype == VG_PATH_DATATYPE_F);
			float data[26];
			for(int i=0;i<numCoordinates;i++)
				data[i] = (float)((coordinates[i] - bias) / scale);
			vgAppendPathData(path, numSegments, segments, data);
			break;
		}
	}
}
Ejemplo n.º 2
0
bool LuaSimpleContext::callFunc( const char* name, const FunctionCallArgs& args, bool ignore_non_existent )
{
    const int stack_size_before = lua_gettop(m_pimpl->L);

    lua_getglobal(m_pimpl->L, name);
    if (lua_isfunction(m_pimpl->L, -1) != 1)
    {
        if (!ignore_non_existent)
        {
            log_error("Could not call function '%s' with %d args: no such function exist in context '%s'",
                      name, args.args.size(), getName().c_str());
        }

        lua_pop(m_pimpl->L, 1);
        return false;
    }

    for (size_t i = 0; i < args.args.size(); ++i)
    {
        const FunctionCallArg& arg = args.args[i];

        if (arg.is_number)
            lua_pushnumber(m_pimpl->L, arg.number_value);
        else if (arg.object_ref.isSet())
            pushNewObjectRef(m_pimpl->L) = arg.object_ref;
        else
            lua_pushstring(m_pimpl->L, arg.str_value.c_str());
    }

    // TODO: pcall error handler (last argument of lua_pcall) with more debug info like callstack
    const int result = lua_pcall(m_pimpl->L, args.args.size(), 0, 0);
    if (result != 0)
    {
        const char* error_str = lua_tostring(m_pimpl->L, -1);
        log_error("Error when executing function '%s' with %d args in context '%s': %s",
                  name, args.args.size(), getName().c_str(), error_str);
        lua_pop(m_pimpl->L, 1);

        MK_ASSERT(lua_gettop(m_pimpl->L) == stack_size_before);
        return false;
    }

    m_pimpl->increaseValidationIdx();

    MK_ASSERT(lua_gettop(m_pimpl->L) == stack_size_before);

    return true;
}
Ejemplo n.º 3
0
void LuaSimpleContext::registerFuncImpl( const char* name, lua_CFunction proxy_fun_ptr )
{
    int index = LUA_GLOBALSINDEX;
    if (isRegisteringInNamespace())
    {
        // Lua stack after this lua_getglobal:
        // [-1] table to register in
        // [-2] upvalue for c closure
        // we need to swap them, so lua_pushcclosure can proceed:
        // [-1] upvalue for c closure
        // [-2] table to register in
        // After lua_pushcclosure, stack will look like this:
        // [-1] c closure
        // [-2] table to register in
        lua_getglobal(_getLuaState(), m_currentRegistrationNamespace.c_str());
        lua_insert(_getLuaState(), -2);

        index = -2;
    }

    lua_pushcclosure(_getLuaState(), proxy_fun_ptr, 1);

    MK_ASSERT(lua_istable(_getLuaState(), index) || index == LUA_GLOBALSINDEX);
    lua_setfield(_getLuaState(), index, name);

    if (isRegisteringInNamespace())
        lua_pop(_getLuaState(), 1);
}
Ejemplo n.º 4
0
void Level::findObjectsInRadius( TGameObjectVec& out_objects, const rtti::TypeInfo* type, const mkVec3& search_origin, float radius, bool allow_derived /*= true*/ )
{
    MK_ASSERT(out_objects.empty());

    m_objectsMgr.findObjectsOfType(out_objects, type, allow_derived);

    for (size_t i = 0; i < out_objects.size(); ++i)
    {
        bool accept = false;

        GameObject* go = out_objects[i];
        if (go->getTypeInfo()->isDerivedOrExact(&ModelObject::Type))
        {
            ModelObject* mo = static_cast<ModelObject*>(go);
            float dist_sq = (mo->getWorldPosition() - search_origin).length();

            if (dist_sq <= radius)
                accept = true;
        }

        if (!accept)
            out_objects[i] = NULL;
    }

    fast_remove_val_from_vec(out_objects, (GameObject*)NULL);
}
Ejemplo n.º 5
0
	void OpenGLContext::checkGLError() {
		
		int err = glGetError();
		
		
		const char* RVAL = "GL_UNKNOWN_ERROR";
		
		switch( err )
		{
			case GL_NO_ERROR:
				RVAL =  "GL_NO_ERROR";
				break;
			case GL_INVALID_ENUM:
				RVAL =  "GL_INVALID_ENUM";
				break;
			case GL_INVALID_VALUE:
				RVAL =  "GL_INVALID_VALUE";
				break;
			case GL_INVALID_OPERATION:
				RVAL = "GL_INVALID_OPERATION";
				break;
			case GL_STACK_OVERFLOW:
				RVAL =  "GL_STACK_OVERFLOW";
				break;
			case GL_STACK_UNDERFLOW:
				RVAL =  "GL_STACK_UNDERFLOW";
				break;
			case GL_OUT_OF_MEMORY:
				RVAL =  "GL_OUT_OF_MEMORY";
				break;
			default:
				break;
		}
		
		if( err != GL_NO_ERROR ) {
			printf("GL_ERROR: %s\n", RVAL );
			MK_ASSERT(0);
		}
	}	
Ejemplo n.º 6
0
    LuaSimpleBindingTest()
    {
        uint8* text = NULL;
        uint32 size = 0;

        if (!loadFile("lua_test.lua", &text, &size, true))
            return;

        lua_simple::LuaSimpleContext context;

        context.runString((const char*)text);

        int32 test_i = 0;
        uint32 test_u = 0;
        float test_f = 0;
        mkString test_s;
        uint8 test_bytes[4] = {0};

        context.registerFunc("getFoo", getFoo);
        context.registerFunc("printFoo", printFoo);

        bool success = true;

        success &= context.callFunc("onInit");

        {
            lua_simple::FunctionCallArgs args;
            args.add(1.23f);
            args.add(2);
            success &= context.callFunc("onUpdate", args);
        }

        success &= context.getGlobalVariable("test_int32").readInt32(test_i);
        success &= context.getGlobalVariable("test_uint32").readUInt32(test_u);
        success &= context.getGlobalVariable("test_float").readFloat(test_f);
        success &= context.getGlobalVariable("test_string").readString(test_s);
        success &= context.getGlobalVariable("test_bytes").readBytes(4, test_bytes);

        {
            lua_simple::FunctionCallArgs args;
            args.add("dupa slonia");
            success &= context.callFunc("onTakeDamage", args);
        }

        context.registerFunc("testCFunc", test);
        context.registerFunc("testCFunc2", test2);
        //context.registerFunc("testCFunc3", test3);
        context.registerFunc("testCFunc4", test4);
        context.registerFunc("testCFunc5", test5);

        success &= context.callFunc("testMyTest");

        success &= context.getGlobalVariable("dupa").getVariableByKey("jeden").readInt32(test_i);

        success &= context.getGlobalVariable("test_int32").readInt32(test_i);
        success &= context.getGlobalVariable("test_uint32").readUInt32(test_u);
        success &= context.getGlobalVariable("test_float").readFloat(test_f);
        success &= context.getGlobalVariable("test_string").readString(test_s);
        success &= context.getGlobalVariable("test_bytes").readBytes(4, test_bytes);

        //success &= context.getGlobalVariable("test_int32").writeInt32(987);
        //success &= context.getGlobalVariable("test_int32").readInt32(test_i);

        MK_ASSERT(success);

        delete[] text;
    }