Example #1
0
static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    FunctionInstance *function;
    IDispatch *this_obj = NULL;
    unsigned cnt = 0;
    HRESULT hres;

    TRACE("\n");

    if(!(function = function_this(jsthis)))
        return throw_type_error(ctx, JS_E_FUNCTION_EXPECTED, NULL);

    if(argc) {
        if(!is_undefined(argv[0]) && !is_null(argv[0])) {
            hres = to_object(ctx, argv[0], &this_obj);
            if(FAILED(hres))
                return hres;
        }

        cnt = argc-1;
    }

    hres = call_function(ctx, function, this_obj, cnt, argv+1, r);

    if(this_obj)
        IDispatch_Release(this_obj);
    return hres;
}
Example #2
0
 inline Integer* to_integer(ObjP p)
 {
     if (is_object(p))
         return to_object(p)->cast_integer();
     else
         if (is_fixnum(p))
             return new Integer(fixnum_to_int(p));
     throw new Exception("bad_integer", p);
 }
	void main_3delight(void *arg)
	{
		if( bumpInterp() == 0 )
		{
			normal n = outNormal();
			/* Bump. */
			do_bump_map(
				//bumpValue(),
				//bumpDepth(),
				normalCamera(),
				n );
			outNormal() = n;
		}
		else if( bumpInterp() == 1 )
		{
			///* Tangent Space Normals. */
			//vector udir, vdir;

			//if( stangent != vector(0) )
			//{
			//	vdir = stangent ^ i_normalCamera;
			//}
			//else
			//{
			//	vdir = Du(tt) * dPdu + Dv(tt) * dPdv;
			//	vdir = i_normalCamera ^ (vdir ^ i_normalCamera);
			//}

			//udir = i_normalCamera ^ vdir;
			//vector uorient = Du(ss) * dPdu + Dv(ss) * dPdv;
			//if( udir.uorient < 0 )
			//{
			//	udir = -udir;
			//}

			//vector basisx = normalize(udir);
			//vector basisy = normalize(vdir);
			//vector basisz = normalize(i_normalCamera);

			//outNormal() = normal(
			//	(bumpNormal().x - 0.5f) * basisx +
			//	(bumpNormal().y - 0.5f) * basisy +
			//	(bumpNormal().z - 0.5f) * basisz );

			//outNormal() = normalize(outNormal());
		}
		else
		{
			/* Object Space Normals. This needs some work. */
			//outNormal() = ntransform( "object", "current", bumpNormal() - 0.5f );
			//outNormal() = normalize(outNormal());
			matrix toObject = to_object();
			vector tmp = (bumpNormal() - normal(0.5f,0.5f,0.5f)) * toObject;
			outNormal() = normalize(tmp);
		}
	}
Example #4
0
static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
    FunctionInstance *function;
    DISPPARAMS args = {NULL,NULL,0,0};
    DWORD argc, i;
    IDispatch *this_obj = NULL;
    HRESULT hres = S_OK;

    TRACE("\n");

    if(!(function = function_this(jsthis)))
        return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);

    argc = arg_cnt(dp);
    if(argc) {
        VARIANT *v = get_arg(dp,0);

        if(V_VT(v) != VT_EMPTY && V_VT(v) != VT_NULL) {
            hres = to_object(ctx, v, &this_obj);
            if(FAILED(hres))
                return hres;
        }
    }

    if(argc >= 2) {
        jsdisp_t *arg_array = NULL;

        if(V_VT(get_arg(dp,1)) == VT_DISPATCH) {
            arg_array = iface_to_jsdisp((IUnknown*)V_DISPATCH(get_arg(dp,1)));
            if(arg_array &&
               (!is_class(arg_array, JSCLASS_ARRAY) && !is_class(arg_array, JSCLASS_ARGUMENTS) )) {
                jsdisp_release(arg_array);
                arg_array = NULL;
            }
        }

        if(arg_array) {
            hres = array_to_args(ctx, arg_array, ei, caller, &args);
            jsdisp_release(arg_array);
        }else {
            FIXME("throw TypeError\n");
            hres = E_FAIL;
        }
    }

    if(SUCCEEDED(hres))
       hres = call_function(ctx, function, this_obj, &args, retv, ei, caller);

    if(this_obj)
        IDispatch_Release(this_obj);
    for(i=0; i<args.cArgs; i++)
        VariantClear(args.rgvarg+i);
    heap_free(args.rgvarg);
    return hres;
}
Example #5
0
 inline int int_value(ObjP p)
 {
     if (is_object(p))
     {
         Integer* integer = to_object(p)->cast_integer();
         return integer->int_value();
     }
     else
         if (is_fixnum(p))
             return fixnum_to_int(p);
     throw new Exception("bad_integer", p);
 }
Example #6
0
static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
{
    FunctionInstance *function;
    jsval_t *args = NULL;
    unsigned i, cnt = 0;
    IDispatch *this_obj = NULL;
    HRESULT hres = S_OK;

    TRACE("\n");

    if(!(function = function_this(jsthis)))
        return throw_type_error(ctx, JS_E_FUNCTION_EXPECTED, NULL);

    if(argc) {
        if(!is_undefined(argv[0]) && !is_null(argv[0])) {
            hres = to_object(ctx, argv[0], &this_obj);
            if(FAILED(hres))
                return hres;
        }
    }

    if(argc >= 2) {
        jsdisp_t *arg_array = NULL;

        if(is_object_instance(argv[1])) {
            arg_array = iface_to_jsdisp((IUnknown*)get_object(argv[1]));
            if(arg_array &&
               (!is_class(arg_array, JSCLASS_ARRAY) && !is_class(arg_array, JSCLASS_ARGUMENTS) )) {
                jsdisp_release(arg_array);
                arg_array = NULL;
            }
        }

        if(arg_array) {
            hres = array_to_args(ctx, arg_array, &cnt, &args);
            jsdisp_release(arg_array);
        }else {
            FIXME("throw TypeError\n");
            hres = E_FAIL;
        }
    }

    if(SUCCEEDED(hres))
        hres = call_function(ctx, function, this_obj, cnt, args, r);

    if(this_obj)
        IDispatch_Release(this_obj);
    for(i=0; i < cnt; i++)
        jsval_release(args[i]);
    heap_free(args);
    return hres;
}
Example #7
0
ObjectFoundation* PingFlow::find_by_id(unsigned int id, DBManager &dbm)
{
    char sql[500];
    sprintf(sql, "SELECT * FROM %s WHERE `pingId`='%d';", this->get_table_name().c_str(), id);
    dbm.sql_execute(sql);
    m_sql_list sql_list = dbm.get_sql_res();
    m_sql_object sql_object;
    if (sql_list.size()==0) {
        std::cout << "Object not found!" << std::endl;
        return NULL;
    } else {
        m_sql_list::iterator iter = sql_list.begin();
        return to_object(*iter);
    }
}
	void do_bump_map(
		//const eiScalar i_bumpValue,
		//const eiScalar i_bumpDepth,
		const normal& i_normalCamera,
		normal& o_outNormal )
	{
		eiScalar LOW = -1.0f, HEIGHT=1.0f;
		eiScalar offset = clamp(bumpValue(), LOW, HEIGHT) * abs(bumpDepth());

		//Du_offset=d(offset)/du, Dv_offset=d(offset)/dv
		eiScalar Du_offset, Dv_offset;
		eiScalar DbumpValue_du, DbumpValue_dv;
		eiScalar DbumpDepth_du, DbumpDepth_dv;		
		Du(bumpValue, DbumpValue_du);
		Dv(bumpValue, DbumpValue_dv);
		Du(bumpDepth, DbumpDepth_du);
		Dv(bumpDepth, DbumpDepth_dv);
		Du_offset = D_clamp(bumpValue(), LOW,HEIGHT) * DbumpValue_du      * abs(bumpDepth()) 
			        + clamp(bumpValue(), LOW,HEIGHT) * D_abs(bumpDepth()) * DbumpDepth_du;
		Dv_offset = D_clamp(bumpValue(), LOW,HEIGHT) * DbumpValue_dv      * abs(bumpDepth()) 
			        + clamp(bumpValue(), LOW,HEIGHT) * D_abs(bumpDepth()) * DbumpDepth_dv;
		/*
		These scale factors are a bit experimental. The constant is to roughly
		match maya's bump mapping. The part about dPdu/dPdv ensures that the
		bump's scale does not depend on the underlying parametrization of the
		patch (the use of Du and Dv below introduce that) and that it happens
		in object space. Note that maya's handling of object space appears to
		be slightly broken since an enlarged sphere will have the same bump as
		a sphere with its control points moved outwards by a scale, somehow.
		*/
		matrix toLocal = to_object();
		eiScalar uscale = 1.0f / len(&(dPdu() * toLocal)) * 6.0f;
		eiScalar vscale = 1.0f / len(&(dPdv() * toLocal)) * 6.0f;

		vector gu = vector(1.0f, 0.0f, Du_offset * uscale);
		vector gv = vector(0.0f, 1.0f, Dv_offset * vscale);
		normal n = normal(gu ^ gv);

		vector basisz = normalize(i_normalCamera);
		vector basisx = normalize((basisz ^ dPdu()) ^ basisz);
		vector basisy = normalize((basisz ^ dPdv()) ^ basisz);

		o_outNormal = normal(
			n.x * basisx + n.y * basisy + n.z * basisz);

		o_outNormal = normalize(o_outNormal);
	}
Example #9
0
File: _wc.c Project: ehershey/pd
int cmd_wc(string str)
{
  object *weapons;
  string *wielded_by;
  string *wielding_limbs;
  object wtemp;
  object ob;
  int i, wlsize, z;

  if((!str) || !(ob = to_object(str)))
  {
    notify_fail("Find WC of what object?  See \"help format\"\n");
    return 0;
  }
  if(!living(ob))
  { /* must be a weapon */
    write("Querying " + str + "  " + ob->query_short() + "\n");
    write("WC: " + ob->query_wc() + "\n");
    return 1;
  }

  weapons = ({});
Example #10
0
mixed cmd(string str) {
    int i;
    mixed justvars, tmp;
    string cmd, what, ret = "";;

    if(!this_player() || !archp(this_player())){
        write("Sorry, this is an arch command.");
        return 1;
    }

    if(!str || str == ""){
        return GetHelp();
    }

    tmp = DEFINES_D->GetDefine(str);
    if(tmp) str = tmp;

    what = str;
    ob = to_object(what);

    if(!ob){
        string path = this_player()->query_cwd()+"/";
        if(last(what,2) != ".c") what += ".c";
        if(file_exists(what)) ob = load_object(what);
        else if(file_exists(path+what)) ob = load_object(path+what);
    }

    if(!ob){
        write(truncate(what,2)+" not found.");
        return 1;
    }

    justvars = variables(ob);

    foreach(ele in justvars){
        i = catch( tmp = evaluate(bind( (: fetch_variable($(ele)) :), ob)) );
        if(!i) write(ele + " " + identify(tmp));
    }
Example #11
0
mixed cmd(string args) {
    object *inv;
    object ob;
    string tmp;
    int scan, i, maxi;

    if( args == "" || !args ) {
        ob = this_player();
        scan = 0;
    }
    else {
        while(args[0] == '-') {
            switch(args[1]) {
            case 'd': scan |= OPT_D; break;
            case 'e': scan |= OPT_E; break;
            case 'i': scan |= OPT_I; break;
            case 'f': scan |= OPT_F; break;
            }
            if( strlen(args) > 3 ) args = trim(args[2..]);
            else args = "";
        }
        if( args != "" ) ob = to_object(args);
        if( !ob ) ob = this_player();
    }
Example #12
0
static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
    FunctionInstance *function;
    DISPPARAMS args = {NULL,NULL,0,0};
    IDispatch *this_obj = NULL;
    DWORD argc;
    HRESULT hres;

    TRACE("\n");

    if(!(function = function_this(jsthis)))
        return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL);

    argc = arg_cnt(dp);
    if(argc) {
        VARIANT *v = get_arg(dp,0);

        if(V_VT(v) != VT_EMPTY && V_VT(v) != VT_NULL) {
            hres = to_object(ctx, v, &this_obj);
            if(FAILED(hres))
                return hres;
        }

        args.cArgs = argc-1;
    }

    if(args.cArgs)
        args.rgvarg = dp->rgvarg + dp->cArgs - args.cArgs-1;

    hres = call_function(ctx, function, this_obj, &args, retv, ei, caller);

    if(this_obj)
        IDispatch_Release(this_obj);
    return hres;
}
Example #13
0
void IdleAction::update(unsigned int time) {

	// auto task searching
	if (this->entity->location &&
	    this->entity->has_attribute(attr_type::owner) &&
	    this->entity->has_attribute(attr_type::attack) &&
	    this->entity->get_attribute<attr_type::attack>().stance != attack_stance::do_nothing) {

		// restart search from new tile when moved
		auto terrain = this->entity->location->get_terrain();
		auto current_tile = this->entity->location->pos.draw.to_tile3().to_tile();
		if (!(current_tile == this->search->start_tile())) {
			this->search = std::make_shared<TerrainSearch>(terrain, current_tile, 5.0f);
		}

		// search one tile per update
		// next tile will always be valid
		coord::tile tile = this->search->next_tile();
		auto tile_data = terrain->get_data(tile);
		auto &player = this->entity->get_attribute<attr_type::owner>().player;

		// find and actions which can be invoked
		for (auto object_location : tile_data->obj) {
			Command to_object(player, &object_location->unit);

			// only allow abilities in the set of auto ability types
			to_object.set_ability_set(auto_abilities);
			if (this->entity->invoke(to_object)) {
				break;
			}
		}
	}

	// inc frame
	this->frame += time * this->frame_rate / 20.0f;
}
Example #14
0
File: var.c Project: arylwen/terebi
int cmd(string str) {
    int i;
    mixed ret;
    string cmd, what;

    if(!str || str == ""){
        help();
        return 1;
    }

    i = sscanf(str,"%s %s %s", cmd, var, what);

    if(i != 3 || (cmd != "get" && cmd != "set")){
        help();
        return i;
    }

    if(cmd == "set"){
        int tmp;
        i = sscanf(what,"%s %s", newval, what);
        if(i != 2){
            help();
            return i;
        }
        if(sscanf(newval,"%d",tmp)) newval = tmp;
    }

    ob = to_object(what);

    if(!ob){
        string path = this_player()->query_cwd()+"/";
        if(last(what,2) != ".c") what += ".c";
        if(file_exists(what)) ob = load_object(what);
        else if(file_exists(path+what)) ob = load_object(path+what);
    }

    if(!ob){
        write(truncate(what,2)+" not found.");
        return 1;
    }

    if(!CheckVar(var, ob)){
        write("No such variable exists in that object.");
        return 1;
    }

    i = catch( ret = evaluate(bind( (: fetch_variable($(var)) :), ob)) );

    if(i){
        write("Error in variable query.");
        return 1;
    }

    write(var+" in "+identify(ob)+" is "+identify(ret));

    if(cmd == "get"){
        return 1;
    }

    if(cmd == "set"){
        evaluate(bind( (: store_variable($(var), $(newval)) :), ob));
        ret = evaluate(bind( (: fetch_variable($(var)) :), ob));
        write(var+" in "+identify(ob)+" is now "+identify(ret));
        return 1;
    }
Example #15
0
 inline Code* to_code(ObjP p)
 {
     if (is_object(p))
         return to_object(p)->cast_code();
     throw new Exception("bad_type", p);
 }