Hi, I have a design issue for configuration, which I can't find a solution to. Before scratching it and rewriting it (which is how I usually solve my problems), I'd like input.
At the start of my program I create a map of variables and their default values, then set the variables according to command line flags, so now I have a mix of default and user set values, which is ideally what you want. Now, I then have a separate configuration tree that I load these values in to, however, I load a file containing previous config stuff before or after I load the variable map in to. The problem is, the configuration file overwrites variable map values, or the variables map overwrites the configuration file values.
I currently have it in my head visualized as trying to overlay two opaque images, thinking I need to set some values to transparent. Yet I'm not sure how I'd do this. Here's some code:
[cpp] opt::options_description desc(l10n("Options"));
desc.add_options()
("help,h",
l10n("Shows this help message."))
("config,c",
opt::value<std::string>()->default_value(defaultConfig),
l10n("Sets the configuration file to use."))
("width,W",
opt::value<int>()->default_value(800),
l10n("Sets the window width."))
("height,H",
opt::value<int>()->default_value(600),
l10n("Sets the window height."))
("fullscreen,F",
l10n("Makes the window fullscreen."));
opt::variables_map variables;
opt::store(opt::parse_command_line(argCount, args, desc), variables);[/cpp]
[cpp] configTree.put("window.width", variables["width"].as<int>());
configTree.put("window.height", variables["height"].as<int>());
configTree.put("window.fullscreen", (variables.count("fullscreen") != 0));
configFile = variables["config"].as<std::string>();
if(boost::filesystem::exists(configFile))
{
loadConfig(configFile, configTree);
}[/cpp]
[QUOTE=Jookia;32721546]Hi, I have a design issue for configuration, which I can't find a solution to. Before scratching it and rewriting it (which is how I usually solve my problems), I'd like input.
At the start of my program I create a map of variables and their default values, then set the variables according to command line flags, so now I have a mix of default and user set values, which is ideally what you want. Now, I then have a separate configuration tree that I load these values in to, however, I load a file containing previous config stuff before or after I load the variable map in to. The problem is, the configuration file overwrites variable map values, or the variables map overwrites the configuration file values.
I currently have it in my head visualized as trying to overlay two opaque images, thinking I need to set some values to transparent. Yet I'm not sure how I'd do this. Here's some code:
[cpp] opt::options_description desc(l10n("Options"));
desc.add_options()
("help,h",
l10n("Shows this help message."))
("config,c",
opt::value<std::string>()->default_value(defaultConfig),
l10n("Sets the configuration file to use."))
("width,W",
opt::value<int>()->default_value(800),
l10n("Sets the window width."))
("height,H",
opt::value<int>()->default_value(600),
l10n("Sets the window height."))
("fullscreen,F",
l10n("Makes the window fullscreen."));
opt::variables_map variables;
opt::store(opt::parse_command_line(argCount, args, desc), variables);[/cpp]
[cpp] configTree.put("window.width", variables["width"].as<int>());
configTree.put("window.height", variables["height"].as<int>());
configTree.put("window.fullscreen", (variables.count("fullscreen") != 0));
configFile = variables["config"].as<std::string>();
if(boost::filesystem::exists(configFile))
{
loadConfig(configFile, configTree);
}[/cpp][/QUOTE]
Have you looked into using a multimap (assuming you are using std::map internally) perhaps?
I'm using Boost's variables map and property tree, so they're pretty foreign to me.
Okay, so I'm slightly stumped.
I have a school assignment on inheritance in Java that I decided to expand a little when finished. I currently have the following classes:
Window, which you probably can't figure out what it has.
Employee, which contains a number of variables and a method that prints said variables.
SectionTwo, which has 2 employees defined and prints them.
Programmer, which has a programmer defined with an extra variable for the language.
Administrator, which has the admin with an extra variable for his rank.
Physician, which houses the physician with a variable for his DEA certificate.
I have a window with buttons for all of those and a text area and I want to make the buttons print the corresponding information in the text area. I try, I try but I figure out how to do this.
I guess you just want to override toString?
[QUOTE=Sir Whoopsalot;32725711]Okay, so I'm slightly stumped.
I have a school assignment on inheritance in Java that I decided to expand a little when finished. I currently have the following classes:
Window, which you probably can't figure out what it has.
Employee, which contains a number of variables and a method that prints said variables.
SectionTwo, which has 2 employees defined and prints them.
Programmer, which has a programmer defined with an extra variable for the language.
Administrator, which has the admin with an extra variable for his rank.
Physician, which houses the physician with a variable for his DEA certificate.
I have a window with buttons for all of those and a text area and I want to make the buttons print the corresponding information in the text area. I try, I try but I figure out how to do this.[/QUOTE]
I suppose you could add actionlisteners to the buttons and then do:
[cpp]
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button1)
{
TextArea.setText(""+Member1+"/*Newline?*/"+Member2);
}
}
[/cpp]
[QUOTE=Nekrietns;32720928]Now, why would one use the %3d and %6.1f thing if you could just put the variables right into printf?[/QUOTE]
Because you need to insert the format markers so printf knows how many parameters you are passing and how they should be shown...?
I don't get this. Why RenderWindow in SFML2 returns frametime as uint?
[QUOTE=Frugle;32729997]I don't get this. Why RenderWindow in SFML2 returns frametime as uint?[/QUOTE]
It's in ms and it's not counted more accurately than with 1 ms precision.
[QUOTE=sim642;32730390]It's in ms and it's not counted more accurately than with 1 ms precision.[/QUOTE]
Well that sucks because it used to return float in seconds that was a lot more accurate.
[QUOTE=Frugle;32731530]Well that sucks because it used to return float in seconds that was a lot more accurate.[/QUOTE]
Uh
You do realize you can convert milliseconds to seconds by doing float sec = (float)ms / 1000.0f;
I'm a beginning C# programmer and i'm (trying) to make a program that calculates different formulas like area, volume and on.
I use 3 radio buttons to switch between 3 groeps of formulas (area, volume and force), if any of them are selected options about them are listed in a listbox (area has as options: triangle, circle, a square, ...).
I can show them if i put the code in a button event, but they won't show if i put them in a method "private void choice ()" (the listbox updates when you select another radio button) the listbox stays empty.
I've tried the update() and refresh() options with the listbox but it doesn't work.
Any sulutions?
(i'm using visual studio)
[QUOTE=ToXiCsoldier;32733463]I'm a beginning C# programmer and i'm (trying) to make a program that calculates different formulas like area, volume and on.
I use 3 radio buttons to switch between 3 groeps of formulas (area, volume and force), if any of them are selected options about them are listed in a listbox (area has as options: triangle, circle, a square, ...).
I can show them if i put the code in a button event, but they won't show if i put them in a method "private void choice ()" (the listbox updates when you select another radio button) the listbox stays empty.
I've tried the update() and refresh() options with the listbox but it doesn't work.
Any sulutions?
(i'm using visual studio)[/QUOTE]
Got the code?
[QUOTE=esalaka;32731959]Uh
You do realize you can convert milliseconds to seconds by doing float sec = (float)ms / 1000.0f;[/QUOTE]
Yes, but milliseconds as uint isn't accurate enough. When frametime is less than 0.5 ms it returns 0 and you can't use that for anything.
For one of my modules I am going to have to work with ARM processors, is there any simulators out there?
Can QEmu be used to simulate?
[QUOTE=Frugle;32742299]Yes, but milliseconds as uint isn't accurate enough. When frametime is less than 0.5 ms it returns 0 and you can't use that for anything.[/QUOTE]
I actually agree on this. You're limited to different intervals on a low frame time, it's like "inf, 1000, 500, 333, 250, 200", etc. This is not very useful if you have a frame time decrease from 700 to 800 frames per second. Because you can't see the increase in any way if you're benchmarking for example, because it's either 1ms or 2ms, it can't be 1.5ms.
The reason might be that the underlying timer has a 1ms precision. As such, float probably just gave the illusion of higher precision.
Alright, I have the following:
[code]particleEngine.EmitterLocation = shuttlePos + new Vector2((float)(Math.Cos(shuttleAngle + (Math.PI / 2)) * -20), (float)(Math.Sin(shutthleAngle + (Math.PI / 2))));[/code]
The particles are emitting on the spaceship fine, and when the spaceship moves the particles move along, but when the spaceship turns, the particles don't. What am I doing wrong?.
Edit:
I've got it to stick on the position by doing the following:
[code]particleEngine.EmitterLocation = shuttlePos + new Vector2((float)(Math.Cos(shuttleAngle - (Math.PI / 2)) * movementSpeed), (float)(Math.Sin(shuttleAngle - (Math.PI / 2)) * movementSpeed));;[/code]
But when I try to move it 20 px lower it will start turning in the opposite direction of the spaceship when I turn it.
[QUOTE=Armandur;32728667]I suppose you could add actionlisteners to the buttons and then do:
[cpp]
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button1)
{
TextArea.setText(""+Member1+"/*Newline?*/"+Member2);
}
}
[/cpp][/QUOTE]
I'm trying to get that done but:
[cpp]
employee.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
output.setText(Daniel.printAll() + Chris.printAll() );
}
});
[/cpp]
gives me an error saying that Daniel and Chris can't be resolved, even though Window extends SectionTwo (where Chris and Daniel are housed).
Hi, I am having a problem with my java programming homework, hopefully someone can help me.
I can get the program to compile but the problem with the program is that it's supposed to loop for as many times as the user wants the program to loop for but the program doesn't output anything and continues to run forever.
[cpp]
import java.util.*; //imports util package
import java.io.*;
import javax.swing.*;
public class Phone2 {
public static int Number(char uppercase){ //names variables
int generate;
int num = 0; //determines what the value of each letter is-------------|
if(uppercase=='A' || uppercase=='B' || uppercase=='C'){
num = 2;
}
else if (uppercase=='D' || uppercase=='E' || uppercase=='F'){
num = 3;
}
else if (uppercase=='G' || uppercase=='H' || uppercase=='I'){
num = 4;
}
else if (uppercase=='J' || uppercase=='K' || uppercase=='L'){
num = 5;
}
else if (uppercase=='M' || uppercase=='N' || uppercase=='O'){
num = 6;
}
else if (uppercase=='P' || uppercase=='Q' || uppercase=='R' ||
uppercase== 'S'){
num = 7;
}
else if (uppercase=='T' || uppercase=='U' || uppercase=='V'){
num = 8;
}
else if (uppercase=='W' || uppercase=='X' || uppercase== 'Y' ||
uppercase== 'Z'){
num = 9;
}
else if (uppercase=='-'){
System.out.print("-");
//If the user inputs a "-" a "-" is outputted
}
else if (uppercase==' '){
System.out.print(" ");//enters a space if a space in inputted
}
return num;
}
//--------------------------------------------------------------------------|
public static void main (String[] args) {
String generate;
Scanner input = new Scanner(System.in);
generate = JOptionPane.showInputDialog("How many phone numbers do you want to generate? ");
int GENERATE = Integer.parseInt(generate);
for (int l = 0; l < GENERATE; l++){
JOptionPane.showInputDialog(
"Enter a string of characters to get its equivalent phone number: ");
//prompts user to enter a word
String phone = input.nextLine();
for (int i = 0; i < phone.length(); i++){
System.out.print(Number(phone.toUpperCase().charAt(i)));
//changes all letters to uppercase if needed
if (i == 6){//begin if
break;
//If the string of characters is over 7 the program will stop at 7
}//end if (i == 6)
}//end for i = 0
}//end for (int l)
System.exit(0);
}//end main
}//end program
[/cpp]
[QUOTE=Frugle;32742299]Yes, but milliseconds as uint isn't accurate enough. When frametime is less than 0.5 ms it returns 0 and you can't use that for anything.[/QUOTE]
If you're under 1ms, your game is running too fast. That's >1000 Hz.
Even if it does return 0 most of the time, it should return 1 occasionally when the timer actually increments and your game should still run perfectly fine.
[CPP]struct MyOwnVertexFormat
{
private Vector3 position;
private Color color;
public MyOwnVertexFormat (Vector3 position, Color color)
{
this.position = position;
this.color = color;
}
public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(sizeof(float) * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0)
);
}
[/CPP]
In C# vertex declarations are identified using this public readonly static method. The JITTER inlines this and precomputes it so retrieving it is relatively fast. Obviously in C++ you cannot rely on such a technique...
What would be a good equivalent design pattern to adopt?
In reply to the above, clamp the speed of your updates or simply change the variable to 1 if it is less than 1.
Hello Facepunch. In an attempt to make a password checker for my first "useful" utility coded in C++. I have come up with this code. However when I run the program it only checks for the first line in the file, and doesn't continue to search until it has found the solution. So the question is, how do I make the program search for the password continuously until it finds the correct one, or the file is empty? I tried using a loop: but that didn't work out too well. Sorry for any silly errors, I am tired :v:
The .txt file i am reading from has every 3-digit number from 001-999 if it matters.
[CODE]// fstreamtest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string line;
string password;
cout << "Enter your password: ";
cin >> password;
fstream myfile ("wordlist.txt");
if (myfile.is_open())
{
getline (myfile,line);
cout << line << endl;
if (line==password)
{
cout << "Solution found. The password is: " << line << endl;
return 0;
}
else if (line!=password)
{
cout << "Could not find the specified password.\n";
return 0;
}
}
myfile.close();
return 0;
}[/CODE]
[editline]13th October 2011[/editline]
The program also assumes the password is a 3-digit number.
First of all, it should be a loop. Second of all, you're returning when the password is wrong.
[QUOTE=Sir Whoopsalot;32742543]I'm trying to get that done but:
[cpp]
employee.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
output.setText(Daniel.printAll() + Chris.printAll() );
}
});
[/cpp]
gives me an error saying that Daniel and Chris can't be resolved, even though Window extends SectionTwo (where Chris and Daniel are housed).[/QUOTE]
Anyone?
Alright, thanks Jookia I'll look into it.
[editline]13th October 2011[/editline]
I have changed it slightly, but I can't figure out why it keeps looping the last line of the .txt file. I thought cin.getline(myfile,line) assumed it was terminated by the new line character in the .txt?
[CODE]if (myfile.is_open())
{
while (line!=password)
{
getline (myfile,line);
cout << line << endl;
}
if (line==password)
{
cout << "Solution found. The password is: " << line << endl;
return 0;
}
}
myfile.close();
return 0;[/CODE]
How would i do "reloading" in XNA? I know its as simple as to just wait when 5 seconds when the ammo reaches zero and then set the ammo to the max ammo, buuuuuuuuut its not that simple anyway.
[editline]haah[/editline]
Why the optimistic?
[editline]haah2[/editline]
Nuu, why you be giving meh odd ratings!
I'm doing something with python, which in comparison to everything else in this thread is :V:
I'm trying to make a script/program with makes the user enter a number (x), and tests it for being a prime number. What I want it to do is see if when x is divided by all the numbers from 2 to the number just before x, if there is any remainders. If there are always remainders, the number will be prime, no remainders, and it's not.
[CODE]def primetest():
n = input('Enter your number for science: ')
if blah blah == 0
print "prime, testing completed"
else:
print " not prime, testing completed"[/CODE]
I know I need to use % :S
[QUOTE=JimJam707;32781963]I'm doing something with python, which in comparison to everything else in this thread is :V:
I'm trying to make a script/program with makes the user enter a number (x), and tests it for being a prime number. What I want it to do is see if when x is divided by all the numbers from 2 to the number just before x, if there is any remainders. If there are always remainders, the number will be prime, no remainders, and it's not.
[CODE]def primetest():
n = input('Enter your number for science: ')
if blah blah == 0
print "prime, testing completed"
else:
print " not prime, testing completed"[/CODE]
I know I need to use % :S[/QUOTE]
Have you seen this? [url]http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes[/url]
It's much more efficient than what you are trying to implement, as well as simpler.
[QUOTE=aerochug;32782869]Have you seen this? [url]http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes[/url]
It's much more efficient than what you are trying to implement, as well as simpler.[/QUOTE]
I'm trying to do what I'm trying to do, because it's been set as optional work at school, but I can't figure it out.
Sorry, you need to Log In to post a reply to this thread.