Exemplo n.º 1
0
ObjectHandle InsertItemCommand::getCommandDescription(const ObjectHandle& arguments) const /* override */
{
	auto handle = GenericObject::create(*definitionManager_);
	assert(handle.get() != nullptr);
	auto& genericObject = (*handle);

	if (!arguments.isValid())
	{
		genericObject.set("Name", "Invalid");
		genericObject.set("Type", "Insert");
		return ObjectHandle(std::move(handle));
	}

	auto pCommandArgs = arguments.getBase<InsertItemCommandArgument>();
	if (!InsertItemCommand_Detail::isValid(pCommandArgs))
	{
		genericObject.set("Name", "Invalid");
		genericObject.set("Type", "Insert");
		return ObjectHandle(std::move(handle));
	}

	genericObject.set("Id", pCommandArgs->key_);
	genericObject.set("Name", "Insert");
	genericObject.set("Type", "Insert");
	genericObject.set("PostValue", pCommandArgs->value_);

	return ObjectHandle(std::move(handle));
}
Exemplo n.º 2
0
bool ModelQtTypeConverter::toVariant( const QVariant & qVariant, Variant & o_variant ) const
{
	if (qVariant.canConvert< QtTableModel * >())
	{
		auto model = qVariant.value< QtTableModel * >();
		o_variant = ObjectHandle( &model->source() );
		return true;
	}

	if (qVariant.canConvert< QtTreeModel * >())
	{
		auto model = qVariant.value< QtTreeModel * >();
		o_variant = ObjectHandle( &model->source() );
		return true;
	}

	if (qVariant.canConvert< QtListModel * >())
	{
		auto model = qVariant.value< QtListModel * >();
		o_variant = ObjectHandle( &model->source() );
		return true;
	}

	if (qVariant.canConvert< QtItemModel * >())
	{
		auto model = qVariant.value< QtItemModel * >();
		o_variant = ObjectHandle( &model->source() );
		return true;
	}

	return false;
}
Exemplo n.º 3
0
ObjectHandle SetItemDataCommand::getCommandDescription(const ObjectHandle& arguments) const /* override */
{
	auto handle = GenericObject::create(*definitionManager_);
	assert(handle.get() != nullptr);
	auto& genericObject = (*handle);

	if (!arguments.isValid())
	{
		genericObject.set("Name", "Invalid");
		genericObject.set("Type", "Data");
		return ObjectHandle(std::move(handle));
	}

	auto pCommandArgs = arguments.getBase<SetItemDataCommandArgument>();
	if (!SetItemDataCommand_Detail::isValid(pCommandArgs))
	{
		genericObject.set("Name", "Invalid");
		genericObject.set("Type", "Data");
		return ObjectHandle(std::move(handle));
	}

	genericObject.set("Name", "Data");
	genericObject.set("Type", "Data");

	const auto& oldValue = (pCommandArgs->oldValue_);
	const auto& newValue = (pCommandArgs->newValue_);
	genericObject.set("PreValue", oldValue);
	genericObject.set("PostValue", newValue);

	return ObjectHandle(std::move(handle));
}
Exemplo n.º 4
0
ObjectHandle MoveItemDataCommand::getCommandDescription(const ObjectHandle& arguments) const /* override */
{
	auto handle = GenericObject::create(*get<IDefinitionManager>());
	assert(handle.get() != nullptr);
	auto& genericObject = (*handle);

	if (!arguments.isValid())
	{
		genericObject.set("Name", "Invalid");
		genericObject.set("Type", "Move");
		return ObjectHandle(std::move(handle));
	}

	auto pCommandArgs = arguments.getBase<MoveItemDataCommandArgument>();
	if (!MoveItemDataCommand_Detail::isValid(pCommandArgs))
	{
		genericObject.set("Name", "Invalid");
		genericObject.set("Type", "Move");
		return ObjectHandle(std::move(handle));
	}

	genericObject.set("Name", "Move");
	genericObject.set("Type", "Move");

	return ObjectHandle(std::move(handle));
}
Exemplo n.º 5
0
//------------------------------------------------------------------------------
ObjectHandle reflectedCast(const ObjectHandle& other, const TypeId& typeIdDest,
                           const IDefinitionManager& definitionManager)
{
	std::shared_ptr<IObjectHandleStorage> storage =
	std::make_shared<ObjectHandleStorageReflectedCast>(other.storage(), typeIdDest, definitionManager);
	return ObjectHandle(storage);
}
Exemplo n.º 6
0
  ObjectHandle ObjectHandle::lookup(ManagedObject *object)
  {
    for (auto it = objectByHandle.begin(); it != objectByHandle.end(); it++) {
      if (it->second.ptr == object) return(ObjectHandle(it->first));
    }

    return(nullHandle);
  }
Exemplo n.º 7
0
	bool toVariant( const QVariant & qVariant, Variant & o_variant ) const override
	{
		if ( static_cast<int>( qVariant.type() ) != static_cast<int>( QMetaType::QObjectStar ))
		{
			return false;
		}

		o_variant = ObjectHandle( qvariant_cast< QObject * >( qVariant ) );
		return true;
	}
Exemplo n.º 8
0
void XMLReader::StackItem::cast(IDefinitionManager& definitionManager)
{
	object = ObjectHandle();
	collection = nullptr;

	if (auto v = value.value<ObjectHandle*>())
	{
		object = *v;
	}
	else if (auto v = value.value<Collection*>())
	{
		collection = v;
	}
	else
	{
		if (auto definition = definitionManager.getDefinition(value.type()->typeId().getName()))
		{
			object = ObjectHandle(&value, definition);
		}
	}
}
Exemplo n.º 9
0
void CompoundCommand::deserialize(ISerializer& serializer)
{
	size_t size = 0;
	serializer.deserialize(size);

	std::string id;
	for (size_t i = 0; i < size; ++i)
	{
		serializer.deserialize(id);
		addCommand(id.c_str(), ObjectHandle());
	}
	getMacroObject().getBase<MacroObject>()->deserialize(serializer);
}
Exemplo n.º 10
0
void TestUIContext::select(std::string id)
{
	std::string oldId = selectedId_;
	selectedId_ = models_.find(id) != models_.end() ? id : NO_ID;
	treeVisible_ = selectedId_ != NO_ID;
	selectedModel_ = treeVisible_ ? models_.at(selectedId_) : ObjectHandle();
	definition_->bindProperty("treeVisible", handle()).setValue(treeVisible_);

	if (oldId != selectedId_)
	{
		auto tree = std::static_pointer_cast<proto::PropertyTreeModel>(selectedTree_);
		tree->setObject(selectedModel_);
	}
}
Exemplo n.º 11
0
pair<ObjectHandle,double> BoundedObject::checkCollision(Pd origin, Vd direction, Object *ignore)
{
    double collision = numeric_limits<double>::infinity();
    //--- We only check lbl rbh, could be improved-----
    Point<double> a = bb.lbl;
    Point<double> b = bb.rth;
    //--- Origin does not have to be rotated
    Point<double> p = (-rotation)*(origin - this->origin);
    //--- Vector only needs to be rotated
    //--- We might need the inverse of rotation here
    Vector<double> v = (-rotation)*direction;
    //--- Now check if we have a collision in the x direction
    double lambda1, lambda2;
    if(v.x != 0){
        lambda1 = (a.x - p.x)/(v.x);
        lambda2 = (b.x - p.x)/(v.x);
        if(insideBox(p + v*lambda1, a, b) && 0 < lambda1 && lambda1 < collision){
            collision = lambda1;
        }
        if (insideBox(p + v*lambda2, a, b) && 0 < lambda2 && lambda2 < collision){
            collision = lambda2;
        }
    }
    //---- y direction
    if(v.y != 0){
        lambda1 = (a.y - p.y)/(v.y);
        lambda2 = (b.y - p.y)/(v.y);
        if(insideBox(p + v*lambda1, a, b) && 0 < lambda1 && lambda1 < collision){
            collision = lambda1;
        }
        if(insideBox(p + v*lambda2,a,b) && 0 < lambda2 && lambda2 < collision){
            collision = lambda2;
        }
    }
    //--- z direction
    if(v.z != 0){
        lambda1 = (a.z - p.z)/(v.z);//intersection with axis in lbl.z
        lambda2 = (b.z - p.z)/(v.z);
        if(insideBox(p + v*lambda1, a, b) && 0 < lambda1 && lambda1 < collision){
            collision = lambda1;
        }
        if(insideBox(p + v*lambda2, a, b) && 0 < lambda2 && lambda2 < collision){
            collision = lambda2;
        }
    }
    return make_pair(ObjectHandle(),collision);
}
Exemplo n.º 12
0
	void erase( const PropertyAccessor & pa, const Variant & eraseKey )
	{
		Key key;
		if (!createKey( pa, key ))
		{
			pa.erase( eraseKey );
			return;
		}

		std::unique_ptr<ReflectedCollectionEraseCommandParameters> commandParameters( new ReflectedCollectionEraseCommandParameters() );
		commandParameters->id_ = key.first;
		commandParameters->path_ = key.second;
		commandParameters->key_ = eraseKey;

		const auto itr = commands_.emplace( std::pair< Key, CommandInstancePtr >( key, commandManager_.queueCommand(
			getClassIdentifier<ReflectedCollectionEraseCommand>(), ObjectHandle( std::move( commandParameters ) ) ) ) );

		commandManager_.waitForInstance( itr->second );
		commands_.erase( itr );
	}
Exemplo n.º 13
0
ObjectHandle World::trace(Point<double> origin, Vector<double> &path, Object* ignore)
{
	pair<ObjectHandle, double> closest = make_pair(ObjectHandle(), !path);
	BoundedObject *bo;
	pair<ObjectHandle, double> ret;
	for (Object::iterator it = begin(); it != end(); ++it)
	{
		if (!(bo = TO(BoundedObject,*it))) continue;
		if((!TO(Player, *it) && !TO(Terrain, *it)) || TO(Object, *it) == ignore) continue;
		ret = bo->checkCollision(origin, ~path, ignore);
		if (ret.second < closest.second){
			closest = ret;
			if(!TO(Terrain, *it)){
				closest.first = *it;
			}
		}
	}
	path = ~path * closest.second;
	return closest.first;
}
Exemplo n.º 14
0
//------------------------------------------------------------------------------
ObjectHandle reflectedRoot(const ObjectHandle& source, const IDefinitionManager& definitionManager)
{
	if (!source.isValid())
	{
		return source;
	}

	auto root = source.storage();
	auto reflectedRoot = definitionManager.getObjectDefinition(root) != nullptr ? root : nullptr;
	for (;;)
	{
		auto inner = root->inner();
		if (inner == nullptr)
		{
			break;
		}
		root = inner;
		reflectedRoot = definitionManager.getObjectDefinition(root) != nullptr ? root : nullptr;
	}
	return ObjectHandle(reflectedRoot);
}
Exemplo n.º 15
0
void Build()
{
	Camera &cam = game.controller->camera;
	GridPoint clicked = game.world->terrain->getGridCoordinates(cam.origin, cam.objective);
	if(clicked.isValid())
	{
		#ifdef AUTOBUILD
		int structure = game.world->terrain->canPlaceStructure(clicked);
		ObjectHandle tower;
		switch(structure){
		case 1: case 11: tower = Objects::DefenseTower(game.player->id); break;
		case 2: case 12: tower = Objects::ResourceMine(game.player->id); break;
		case 3: case 13: tower = Objects::RichResourceMine(game.player->id); break;
		default: tower = ObjectHandle();
		}
		Resource cost = 0;
		if(tower){
			Building *b = TO(Building, tower);
			if(b) cost = b->cost;
		}
		map<unsigned char,Team>::iterator it = Game::game.teams.find(Game::game.player->team);
		if(it != Game::game.teams.end()){
			if(it->second.resources >= cost){
				game.world->terrain->setSelected(GridPoint(-1, -1));
				if (!game.world->terrain->placeStructure(clicked, tower)){
					Echo("There's already a tower there");
				}else{
					NetCode::Build(clicked,TO(Structure,tower));
					it->second.resources -= cost;
				}
			}else{
				Echo("You don't have enough money");
			}
		}
		#endif
	}
	else
		Echo("Invalid place to build");
}
Exemplo n.º 16
0
	Variant invoke( const PropertyAccessor & pa, const ReflectedMethodParameters & parameters )
	{
		Key key;
		if (!createKey( pa, key ))
		{
			return pa.invoke( parameters );
		}

		std::unique_ptr<ReflectedMethodCommandParameters> commandParameters( new ReflectedMethodCommandParameters() );
		commandParameters->setId( key.first );
		commandParameters->setPath( key.second.c_str() );
		commandParameters->setParameters( parameters );

		const auto itr = commands_.emplace( std::pair< Key, CommandInstancePtr >( key, commandManager_.queueCommand(
			getClassIdentifier<InvokeReflectedMethodCommand>(), ObjectHandle( std::move( commandParameters ),
			pa.getDefinitionManager()->getDefinition<ReflectedMethodCommandParameters>() ) ) ) );

		commandManager_.waitForInstance( itr->second );
		ObjectHandle returnValueObject = itr->second.get()->getReturnValue();
		commands_.erase( itr );
		Variant* returnValuePointer = returnValueObject.getBase<Variant>();
		assert( returnValuePointer != nullptr );
		return *returnValuePointer;
	}
Exemplo n.º 17
0
ObjectHandle TriPatchObject::CreateTriObjRep(TimeValue t) {
	TriObject *tri = CreateNewTriObject();
	PrepareMesh(t);	// Turn it into a mesh
	tri->GetMesh() = patch.GetMesh();	// Place it into the TriObject
	return(ObjectHandle(tri));
	}
Exemplo n.º 18
0
ObjectHandle BoundedObject::checkCollision2(Pd origin, Vd direction)
{
    return ObjectHandle();
}
Exemplo n.º 19
0
void Fire()
{
	if (!game.input->grabbing) return; // Ignore when not selected
	if (!NetCode::TryLock())
	{
		game.firing = true;
		return;
	}
	game.firing = false;
	switch (game.player->weapon)
	{
		case weapWrench:
			Build();
			return;
		case weapLaser:
		{
		        Camera &cam = game.controller->camera;
			Vd vec = ~(game.player->rotation * Vd(0,1,0));
			double yaw = atan2(vec.x, vec.y);
			Pd gunLoc = game.player->origin;// + game.player->model.weapon->origin;
			gunLoc.x = gunLoc.x + game.player->model.weapon->origin.x * cos(yaw)
			                    + game.player->model.weapon->origin.y * sin(yaw);
			gunLoc.y = gunLoc.y + game.player->model.weapon->origin.x * sin(yaw)
			                    + game.player->model.weapon->origin.y * cos(yaw);
			gunLoc.z = gunLoc.z + game.player->model.weapon->origin.z;
			
			Vd lookVec = (~(Vd(game.controller->target)+ -Vd(cam.origin))) * 38;
			Pd target = game.controller->target;
			ObjectHandle collision;
			if(game.controller->firstPerson){
				lookVec = (~(game.controller->camAngle * Vd(0,1,0)))*38;
				collision = game.world->trace(game.controller->camera.origin, lookVec, game.player);
			}else{
				collision = game.world->trace(game.controller->target, lookVec, game.player);
			}
			if (collision)
			{	
				Pd collisionPoint;
				if(game.controller->firstPerson){
					collisionPoint = game.controller->camera.origin + (lookVec);
				}else{
					collisionPoint = game.controller->target + (lookVec);
				}
				Qd beam = gunLoc.lookAt(collisionPoint);
				
				ObjectHandle laser = LaserBeam(gunLoc, beam, !lookVec);
				game.world->addLaserBeam(laser);
				NetCode::Fire(*TO(LaserBeam,laser));
				Player *p = TO(Player, collision);
				if(p){
					//if(p->team != game.player->team){//Precent teamkill
						p->damage(10.0, game.player->id);
						NetCode::Hit(p->id, 10.0, true);
					//}
				}else{
					Building *b = TO(Building, collision);
					if(b){
						/* Enable team kill on towers to demolish
						Player *own = NULL;
						if(Game::game.players.count(t->owner))
							own = TO(Player, Game::game.players[t->owner]); 
						if(own && own->team != game.player->team){*/
							b->damage(10.0, game.player->id);
							NetCode::Attack(b->loc, 10.0, true);
						//}
					}
				}
			}
			else{
				game.world->addLaserBeam(ObjectHandle(LaserBeam(gunLoc, cam.objective, !lookVec)));
			}
			return;
		}
		break;
	}
}
Exemplo n.º 20
0
ObjectHandle TriObject::CreateTriObjRep(TimeValue t) {
	return(ObjectHandle(this));
	}
Exemplo n.º 21
0
// From Object
ObjectHandle TargetObject::ApplyTransform(Matrix3& matrix){
	return(ObjectHandle(this));
	}