Does anybody here have any links to some really "simple" SFML projects with source code?
I recently downloaded this:
[url]http://www.sfml-dev.org/forum/viewtopic.php?t=3992[/url]
Pretty fuckin' awesome playing around with the code so far. Got tired of command line programs.
Should I use a 64 or 32 bit unsigned integer to store my basic unit of time for my multiplayer game? If I use 32 bit, after about 2.1 years of the server constantly running it will overflow. Is that long enough or should I go with 64 bit?
The integer stores the number of ticks that have elapsed since the server started, where there are 64 ticks in a second.
[editline]21st July 2011[/editline]
[QUOTE=Chrispy_645;31244416]Does anybody here have any links to some really "simple" SFML projects with source code?
I recently downloaded this:
[url]http://www.sfml-dev.org/forum/viewtopic.php?t=3992[/url]
Pretty fuckin' awesome playing around with the code so far. Got tired of command line programs.[/QUOTE]
Here's one I made a while ago:
[url]http://www.sfml-dev.org/forum/viewtopic.php?t=1970[/url]
Download latest version + source: [url]http://robertandsherman.co.uk/downloads/hexpuzzle/hexpuzzle-0-2.zip[/url]
Can someone explain to me the importance of sealed classes in C# and when to use the override keyword properly? This was something I never really understood about C# in particular.
Thanks :D
[QUOTE=Ziks;31247837]Should I use a 64 or 32 bit unsigned integer to store my basic unit of time for my multiplayer game? If I use 32 bit, after about 2.1 years of the server constantly running it will overflow. Is that long enough or should I go with 64 bit?
The integer stores the number of ticks that have elapsed since the server started, where there are 64 ticks in a second.
[editline]21st July 2011[/editline]
Here's one I made a while ago:
[url]http://www.sfml-dev.org/forum/viewtopic.php?t=1970[/url]
Download latest version + source: [url]http://robertandsherman.co.uk/downloads/hexpuzzle/hexpuzzle-0-2.zip[/url][/QUOTE]
I boubt it alot that one same server will be running for 2.1 years non stop.
That said you could always change it in the future with an update
[QUOTE=Ziks;31247837]Should I use a 64 or 32 bit unsigned integer to store my basic unit of time for my multiplayer game? If I use 32 bit, after about 2.1 years of the server constantly running it will overflow. Is that long enough or should I go with 64 bit?[/QUOTE]
I think it's safe to use 4 more bytes of memory to prevent a potential mini-Y2K. I mean, it's highly unlikely you will ever have someone who keeps their server on for 2.1 years, but if you're concerned about it, using 4 bytes of memory and moving on is probably your best bet
Yeah
And the upside is ridiculous uptimes are possible from day one, provided everything is in hotswappable and thus online-updatable modules
How would you essentially say
"If any of the above variables is equal to any other of the above variables, do this"
in Python? Like, is there a sort of range if statement where you can say if x/y/z = x/y/z, do this?
either do something like
[code]
if(x==x) do shiz
if(x==y)...
if(x==z)...
if(y==y)...
if(y==z)...
if(z==z)...
[/code]
or have an array and do
[code]
for(int i = 0; i < first array size; i++)
{
for(int h = 0; h < second array siize; h++)
{
if(firstArray[i] == secondArray[h]) do stuff
}
}
[/code]
[QUOTE=Richy19;31250285]either do something like
[code]
if(x==x) do shiz
if(x==y)...
if(x==z)...
if(y==y)...
if(y==z)...
if(z==z)...
[/code]
or have an array and do
[code]
for(int i = 0; i < first array size; i++)
{
for(int h = 0; h < second array siize; h++)
{
if(firstArray[i] == secondArray[h]) do stuff
}
}
[/code][/QUOTE]
I'm gonna have anything from 10 - 365 variables, so I wanted something a bit more elegant than the first solution :v:
Can you explain the second thing in a bit more detail please?
thanks
[QUOTE=Alcapwne;31250438]I'm gonna have anything from 10 - 365 variables, so I wanted something a bit more elegant than the first solution :v:
Can you explain the second thing in a bit more detail please?
thanks[/QUOTE]
im not 100% sure how python handles arrays but in most languages you can do this.
An array is basically a group of the same type of variables, so you could have say 100 ints in 1 variable
and then access each like myArray[variable number]
that said arrays usually start from 0 so an array holding 100 values would use 0 - 99
Also if you are going to use this method you would want to check that both numbers in the for loops are not the same(or else it would be checking the variable with its self) and if so skip it
[QUOTE=Richy19;31250705]im not 100% sure how python handles arrays but in most languages you can do this.
An array is basically a group of the same type of variables, so you could have say 100 ints in 1 variable
and then access each like myArray[variable number]
that said arrays usually start from 0 so an array holding 100 values would use 0 - 99
Also if you are going to use this method you would want to check that both numbers in the for loops are not the same(or else it would be checking the variable with its self) and if so skip it[/QUOTE]
I understand the concept of arrays but I don't know how I could compare numbers which are in the same array :( I'm going to have an array of say, 50 random integers between say 1 and 50, and I need to see whether any of the numbers in the array is the same
Is that possible?
of course
say you do this
[code]
for(int i = 0; i < array size; i++)
{
for(int h = 0; h < array siize; h++)
{
if(h == i) continue; //skip if both are the same as it would always be true
if(array[i] == array[h]) do stuff
}
}
[/code]
[QUOTE=Richy19;31250908]of course
say you do this
[code]
for(int i = 0; i < array size; i++)
{
for(int h = 0; h < array siize; h++)
{
if(h == i) continue; //skip if both are the same as it would always be true
if(array[i] == array[h]) do stuff
}
}
[/code][/QUOTE]
ah got it :)
Thanks!
Okay, so I'm trying to get a better understanding of pointers through practical application and I'm stuck on something.
[code]
#include <iostream>
int main()
{
using namespace std;
int input[4] = { 25, 10, 5, 1 };
int* Ptr1 = 0;
Ptr1 = &input[0];
cout << *Ptr1 << endl;
++Ptr1;
cout << *Ptr1 << endl;
}
[/code]
Basically, I've found that I can essentially move a pointer through out and array adding/subtracting it to reference different areas of the array.
But how can I use the pointer to reference each part of the array individually?
I want to have it so when someone types in like 1, 2, 3, or 4 (input through cin), the pointer sees the input 1 and it responds by selecting the 25 in the array and outputting the value to the user.
[i]So in essence, I want a user to enter in 1, and the pointer to move to the first part of the array input[0] and then the user receive the output of the value of the array part the pointer is looking at.[/i]
Correct me if I'm wrong at any points of this, I'm essentially trying to make an incredibly simple vending machine thing using an array. (I already achieved this using control statements and switches and I was so proud, but I want to use arrays somehow).
Thanks in advanced.
Me again!
Okay, in Python, how do you print the result of a division?
I've tried the following:
[code]
x += 1
y += 1
print x//y #
[/code]
and
[code]
x += 1
y += 1
print x//y
[/code]
but both methods just return 0 :(
If it helps, I'm using Ironpython, and when I try
[code]
x +=1
y +=1
print x
[/code]
Then it prints it fine, any ideas?
Thanks
[QUOTE=Alcapwne;31252329]Me again!
Thanks[/QUOTE]
use just 1 /
so print x/y
[QUOTE=Richy19;31252553]use just 1 /
so print x/y[/QUOTE]
I did that and it didn't work either, also I read somewhere that that returns integers only, rather than a decimal which is what I'm looking for, no?
[QUOTE=Alcapwne;31252572]I did that and it didn't work either, also I read somewhere that that returns integers only, rather than a decimal which is what I'm looking for, no?[/QUOTE]
Dont know about that, i dont use python.
hmm try puting it inside brackets print(x//y)
[QUOTE=Richy19;31252617]Dont know about that, i dont use python.
hmm try puting it inside brackets print(x//y)[/QUOTE]
I've tried that too :v:
[QUOTE=Alcapwne;31252669]I've tried that too :v:[/QUOTE]
in that case the only other thing i can think of is to do something like:
z = x//y
print z
[QUOTE=Richy19;31253366]in that case the only other thing i can think of is to do something like:
z = x//y
print z[/QUOTE]
Tried that too lol
I've asked it on stackoverflow so I'll post the answer in here if anyone figures it out :v:
[QUOTE=RiceWarrior;31251907]Okay, so I'm trying to get a better understanding of pointers through practical application and I'm stuck on something.
[code]
#include <iostream>
int main()
{
using namespace std;
int input[4] = { 25, 10, 5, 1 };
int* Ptr1 = 0;
Ptr1 = &input[0];
cout << *Ptr1 << endl;
++Ptr1;
cout << *Ptr1 << endl;
}
[/code]
Basically, I've found that I can essentially move a pointer through out and array adding/subtracting it to reference different areas of the array.
But how can I use the pointer to reference each part of the array individually?
I want to have it so when someone types in like 1, 2, 3, or 4 (input through cin), the pointer sees the input 1 and it responds by selecting the 25 in the array and outputting the value to the user.
[i]So in essence, I want a user to enter in 1, and the pointer to move to the first part of the array input[0] and then the user receive the output of the value of the array part the pointer is looking at.[/i]
Correct me if I'm wrong at any points of this, I'm essentially trying to make an incredibly simple vending machine thing using an array. (I already achieved this using control statements and switches and I was so proud, but I want to use arrays somehow).
Thanks in advanced.[/QUOTE]
[code]
int input[4] = { 25, 10, 5, 1 };
int x;
do
{
cout << "Enter a number from 1 to 4: ";
cin >> x;
}
while( x < 0 || x > 4 );
int* Ptr = &input[x];
cout << *Ptr;[/code]
This is how I would do it, if I was using pointers. Although you can also do it without pointers.
I added the do-while loop just for safety, so we can only input a number from 1-4.
Also, thanks for the code Zik. Most appreciated. :smile:
Question about conventions:
When working in 3D with OpenGL, is it convention for a camera facing -Z to mean its normal vector is facing +Z?
If so, should a "forward" unit vector be considered the same as a normal? This came up, because to do a traceline from the camera, we must get the "forward" vector. Depending on whether or not this is the same as the normal, one must multiply by -1.f
[QUOTE=Alcapwne;31252329]Me again!
Okay, in Python, how do you print the result of a division?
I've tried the following:
[code]
x += 1
y += 1
print x//y #
[/code]
and
[code]
x += 1
y += 1
print x//y
[/code]
but both methods just return 0 :(
If it helps, I'm using Ironpython, and when I try
[code]
x +=1
y +=1
print x
[/code]
Then it prints it fine, any ideas?
Thanks[/QUOTE]
Ah apparently if x and y are both integers, Python does integer division by default, so I have to do this instead:
[code]
print float(x)/float(y)
[/code]
for anyone who still cares
[QUOTE=Chrispy_645;31253876][code]
int input[4] = { 25, 10, 5, 1 };
int x;
do
{
cout << "Enter a number from 1 to 4: ";
cin >> x;
}
while( x < 0 || x > 4 );
int* Ptr = &input[x];
cout << *Ptr;[/code]
This is how I would do it, if I was using pointers. Although you can also do it without pointers.
I added the do-while loop just for safety, so we can only input a number from 1-4.
[/QUOTE]
I think I understand what you'd have to do to get this to work, but the only problem is that arrays start from 0 instead of 1 so when you input 1 it gives you the second number in the array, not the first. But this can probably be rectified by changing the array to input[5] { 0, 25, 10, 5, 1} to compensate for the offset. Unless you know of a better way?
The biggest thing that helped me out was this line here:
int* Ptr = &input[x];
Which pretty much cleared up how to create an input that modifies where a pointer is looking.
Thanks a lot, I'll try and put this into use now.
I'm making an extremely basic password program in C++, but it fails to run properly. Can anyone please help?
[code]
#include <iostream>
#include <string>
using namespace std;
int main(){
string input, password = "test";
cout << "Please enter password: " << endl;
getline (cin, input);
if( ( input == password ) )
{
cout << "password accepted.";
cin.get ();
return 0;
}
else if( ( input != password) )
{
cout << "password incorrect. please re-enter the password." << endl;
}
cin.get ();
return 0;
}
[/code]
[QUOTE=RiceWarrior;31254408]I think I understand what you'd have to do to get this to work, but the only problem is that arrays start from 0 instead of 1 so when you input 1 it gives you the second number in the array, not the first. But this can probably be rectified by changing the array to input[5] { 0, 25, 10, 5, 1} to compensate for the offset. Unless you know of a better way?
The biggest thing that helped me out was this line here:
int* Ptr = &input[x];
Which pretty much cleared up how to create an input that modifies where a pointer is looking.
Thanks a lot, I'll try and put this into use now.[/QUOTE]
Shit lol, my bad... you're totally right about that.
[code]int input[4] = { 25, 10, 5, 1 };
int x;
do
{
cout << "Enter a number from 1 to 4: ";
cin >> x;
}
while( x < 0 || x > 4 );
[b]x--;[/b]
int* Ptr = &input[x];
cout << *Ptr;[/code]
Noticed how I added "x--;", so if you typed 4, it will now look at array[3], if you typed 3, it will look at array[2], etc.
You could also just do:
[code]int* Ptr = &input[x-1];[/code]
Which is kinda similar.
@ Mr Smartass, I noticed that it didn't keep repeatedly asking for the password, so I created my own function, outside main():
[code]#include <iostream>
#include <string>
using namespace std;
void Password()
{
string input, password = "test";
getline (cin, input);
if( ( input == password ) )
{
cout << "password accepted.";
cin.get ();
}
else if( ( input != password) )
{
cout << "password incorrect. please re-enter the password." << endl;
Password();
}
}
int main()
{
cout << "Please enter password: " << endl;
Password();
return 0;
}[/code]
If the password is incorrect, the function simply re-calls itself, and you are asked for the password again.
Any SQL gurus out there?
Essentially I need to convert a column's system_type_id to the ADO type. So for example, an int is a system_type_id of 56, but the ADO type is a 3. As far as I can tell there aren't any inbuilt lookups for this purpose.
Is it possible to assign a case in a switch to multiple values in one go?
i.e.
[code]
switch(x)
{
case 0, 1, 2:
{
cout << "blahblah" << endl;
}
}
[/code]
So that whenever 0, 1, or 2 are input into that value they output the same thing. Because using pointers (thanks to Chrispy_645 for the help), the cases can pretty much be the same piece of code over and over but still have a different function because the pointers utilize a separate part of an array. I don't want to have to retype the same code over and over for cases that are identical.
[QUOTE=RiceWarrior;31255946]Is it possible to assign a case in a switch to multiple values in one go?
i.e.
[code]
switch(x)
{
case 0, 1, 2:
{
cout << "blahblah" << endl;
}
}
[/code]
So that whenever 0, 1, or 2 are input into that value they output the same thing. Because using pointers (thanks to Chrispy_645 for the help), the cases can pretty much be the same piece of code over and over but still have a different function because it utilizes a separate part of an array. I don't want to have to retype the same code over and over for cases that are identical.[/QUOTE]
You can use what is usually called "fall-through", which looks like this:
[cpp]switch(x)
{
case 0:
case 1:
case 2:
cout << "Whatever" << endl;
break;
}[/cpp]
Sorry, you need to Log In to post a reply to this thread.