Ejemplo n.º 1
0
void setV(stringstream& lineStream, NodeList& NList) {

	int nodeID;
	double voltage;
	
	if(!anyArgs(lineStream)) return;
	
	lineStream >> nodeID;

		if(!validNode(nodeID, lineStream)) return;
		
	lineStream >> voltage;
	
		if(lineStream.fail()) {
			cout << "Error: " << endl;
			return;
		}
	
	if(!endOfArgs(lineStream)) return;
	
	if(NList.findNode(nodeID) == NULL) NList.insertNode(nodeID);
		
	NList.findNode(nodeID) -> setVoltage(voltage);
		
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout << "Set: node " << nodeID << " to " << setprecision(2) << voltage << setprecision(6) << " Volts" << endl;
	cout.unsetf(ios::fixed);
	cout.unsetf(ios::showpoint);
	
}
Ejemplo n.º 2
0
void modifyR(stringstream& lineStream, NodeList& NList) {

	string name;
	double resistance;

	lineStream >> name;

		if(!anyArgs(lineStream)) return;

		if(name == "all") {
			cout << "Error: resistor name cannot be the keyword \"all\"" << endl;
			return;
		}

	lineStream >> resistance;

		if(!validResistance(resistance, lineStream)) return;

	//check for extra arguments
	if(!endOfArgs(lineStream)) return;
	
	//VALID ARGS
	
	if(NList.modifyR(name, resistance) == false) cout << "Error: resistor " << name << " not found" << endl;  	

	return;
}
Ejemplo n.º 3
0
void unsetV(stringstream& lineStream, NodeList& NList) {

	int nodeID;
	
	if(!anyArgs(lineStream)) return;
	
	lineStream >> nodeID;

		if(!validNode(nodeID, lineStream)) return;
	
	if(!endOfArgs(lineStream)) return;
	
	if(NList.findNode(nodeID) == NULL) cout << "Error: node " << nodeID << " doesn't exist" << endl;
	else {
	
		NList.findNode(nodeID) -> unsetVoltage();
		
		cout << "Unset: the solver will determine the voltage of node " << nodeID << endl;
	} 
	
}
Ejemplo n.º 4
0
Scene* Scene_create(GameEngine* engine, Scene* lastScene) {
    Scene* this = allocStruct(Scene);

    this->engine = engine;
    SDL_Point screenSize;
    SDL_RenderGetLogicalSize(engine->renderer, &screenSize.x, &screenSize.y);
    this->camera = Camera_create(screenSize.x, screenSize.y);
    this->walkableBounds.x = 0;
    this->walkableBounds.w = 0;
    this->walkableBounds.y = 295 * PHYSICS_SCALE;
    this->walkableBounds.h = 185 * PHYSICS_SCALE;

    this->entities = Vector_Create();
    this->triggers = Vector_Create();
    this->bodies = Vector_Create();
    this->shapes = Vector_Create();

    this->sky = Sky_create(engine->textureCache);

    withSprintf(path, "images/%s/bg.png", anyArgs("red"), {
            SDL_Texture* texture = TextureCache_getForUnconstantPath(engine->textureCache, path);
            this->background = Sprite_create(texture);
        });
Ejemplo n.º 5
0
void printR(stringstream& lineStream, NodeList& NList) {

	string name;

	lineStream >> name;

		if(!anyArgs(lineStream)) return;

	if(!endOfArgs(lineStream)) return;
	
	//VALID ARGS

	if(name == "all") { //if "all" go through resistor array and print all resistors

		cout << "Print:" << endl;

    	}

    	else {

    		Resistor* res = NList.findResistor(name);
    		
    		if(res == NULL) {
    		
    			cout << "Error: resistor " << name << " not found" << endl;
    			return;
    		}
		else {
			cout << "Print:" << endl;
			cout << *res << endl;
		}
    	}

	return;

}
Ejemplo n.º 6
0
        this->entity = NULL;
        this->entity = Player_spawnPlayerEntity(this);
    }
    return this->entity;
}

void Player_destroy(void* context) {
    CANCEL_IF_FALSE(context);
    Player* this = context;
    this->controlledEntity.destroyOnRelease = false;
    ControlledEntity_release(&this->controlledEntity);
    free(this);
}

void Player_loadIndicator(Player* this) {
    withSprintf(path, "images/%s/indicator.png", anyArgs("red"), {
        this->controlledEntity.indicator = Sprite_create(TextureCache_getForUnconstantPath(this->scene->engine->textureCache, path));
    });
}

void Player_updateEntity(void* context, RawTime dt) {
}

void Player_destroyEntity(void* context) {
}

void Player_onEntityHealthModified(void* context) {
    //ControlledEntity* ce = context;
    //Player* this = ce->player;
    //Healthbar_set(this->sidebarUi->healthbar, this->entity->health, this->entity->maxHealth);
}
Ejemplo n.º 7
0
void insertR(stringstream& lineStream, NodeList& NList) {

	string name;
	double resistance;
	int nodeID1, nodeID2;

	//Read in each argument one at a time and check for errors
	lineStream >> name;

		if(!anyArgs(lineStream)) return;

		if(name == "all") {
			cout << "Error: resistor name cannot be the keyword \"all\"" << endl;
			return;
		}

	lineStream >> resistance;

		if(!validResistance(resistance, lineStream)) return;

	lineStream >> nodeID1;

		if(!validNode(nodeID1, lineStream)) return;

	lineStream >> nodeID2;

		if(!validNode(nodeID2, lineStream)) return;


	if(nodeID1 == nodeID2) {
		cout << "Error: both terminals of resistor connect to node " << nodeID1 << endl;
		return;
	}

	//check if there are more arguments
	if(!endOfArgs(lineStream)) return;
	
	//VALID ARGUMENTS
	
	//check if nodes exist, if not create
	if(NList.findNode(nodeID1) == NULL) NList.insertNode(nodeID1);
	if(NList.findNode(nodeID2) == NULL) NList.insertNode(nodeID2);
	
	//check if resistor name already exists
	if(NList.findResistor(name) != NULL) {
	
		cout << "Error: resistor " << name << " already exists" << endl;
		return;
	}
        
	//if resistor doesnt exist
	int nodes[2] = {nodeID1, nodeID2};
	NList.addResistor(name, resistance, nodes);
        
    	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout << "Inserted: resistor " << name << " " << setprecision(2) << resistance << " Ohms " << setprecision(6);
	cout.unsetf(ios::fixed);
	cout.unsetf(ios::showpoint);
	cout << nodeID1 << " -> " << nodeID2 << endl;

	return;
}