Little question on delta time and if how I'm thinking about it makes sense.
I have this little bit that increases the player speed when hes falling:
[code]timer += delta;
if (timer >= 20)
{
timer = 0;
ySpeed += .02f;
}[/code]
This gets called every time the player updates and delta is the time since the last update that slick provides. Originally it just added .02f to its speed every tick, but then I ran the game on my desktop and his speed increases to fast. Delta on my desktop is consistently 10, while delta on my laptop was 16-17. So update gets called faster. So I added this to keep it in check.
Now this works fine, but my question is, what if someones computer is so slow that delta is always say 30 on that machine? Then the player might fall noticeably slower. Technically the player falls slower on my laptop then my desktop, but the difference in minimal. So how do I get around this?
I know to move the player like this:
[code]xPos += xSpeed * delta;[/code]
So its the same across all systems, but I dont see how I would do something like that in cases like falling here.
[QUOTE=Eudoxia;37762177]So... Anyone knows how compilers traditionally implement namespaces?[/QUOTE]
My guess is that namespaces are purely for convenience of the programmer. So I would guess you just ignore the namespace and implement the function call as normal.
[QUOTE=ECrownofFire;37765858]My guess is that namespaces are purely for convenience of the programmer. So I would guess you just ignore the namespace and implement the function call as normal.[/QUOTE]
So you end up with two functions in different namespaces having the same name?
I'd say it would be more convenient to store the different functions or whatever somehow. My first idea would be to prepend the name of the namespace to the functions, but then you would have clashes anyway.
I'm not sure how to avoid clashes, but Eudoxia, be sure to keep us posted and post your solution! I'm very very interested!
[QUOTE=ECrownofFire;37765858]My guess is that namespaces are purely for convenience of the programmer. So I would guess you just ignore the namespace and implement the function call as normal.[/QUOTE]
Oh, sure, they are convenience and nothing more. Like templates and what not, they are purely syntactic sugar, but that doesn't necessarily make them simple.
A namespace is, essentially, a way to control how the reader understands symbols. I guess the simplest implementation would be to simply prepend the current namespace and two colons before a symbol name, unless the symbol is already namespaced (ie, find "::" inside the string, or whatever namespace separator you use, find the substring before those two characters and check if it's a valid namespace).
So, if the language core has the namespace "Core", and that is set as the default namespace, then all symbol and function names will have "Core::" prepended to them.
Then, the user does something like this:
[CODE]
(module MyNamespace
...code...)
[/CODE]
And all non-namespaced symbols will have the "MyNamespace::" string attached to them. But what if you want to write the functions you are used to write without remembering to write "Core::" before them? I guess you might either tell the compiler to explicitly use the Core namespace, or something. I dunno. That is what I have so far.
EDIT: Oh, and for clashes, the machine would have to keep a list of symbols in a particular namespace and look for clashes and ways to resolve them. Common Lisp actually has a nice system to do this but I always found it a little overcomplicated - The entire error-handling facility, actually.
I have some design/pattern problem :
I'm making a small networked game in c++ with SFML.
What I want is to have a dedicated server able to run in a console without any graphic environment (headless).
The problem is that my entities classes contains the drawing code and are shared between the server and client. So if I want to run the server in a tty it'll just throw me a segfault because the sfml-window lib can't be properly initialized.
What I need is to remove the drawing code from the entity code so my server can run. I was thinking about a "Render" class that would simply take an entity and then draw it. But my entities use different drawing logic. So the Render class would need a special function for each entity type. I don't like this because the drawing code is "too far from" the entity type and it'll also introduce redundant code.
Do you have any idea how I could separate the drawing code from the entity class and keep it clean ?
[QUOTE=Cyril;37771493]I have some design/pattern problem :
I'm making a small networked game in c++ with SFML.
What I want is to have a dedicated server able to run in a console without any graphic environment (headless).
The problem is that my entities classes contains the drawing code and are shared between the server and client. So if I want to run the server in a tty it'll just throw me a segfault because the sfml-window lib can't be properly initialized.
What I need is to remove the drawing code from the entity code so my server can run. I was thinking about a "Render" class that would simply take an entity and then draw it. But my entities use different drawing logic. So the Render class would need a special function for each entity type. I don't like this because the drawing code is "too far from" the entity type and it'll also introduce redundant code.
Do you have any idea how I could separate the drawing code from the entity class and keep it clean ?[/QUOTE]
If you insist on a hierarchial system, just make a render class for each entity that needs it, and make it implement some generic interface. I do suggest though, that you use a component-based entityt system instead.
[QUOTE=Darkest_97;37762476]Little question on delta time and if how I'm thinking about it makes sense.
I have this little bit that increases the player speed when hes falling:
[code]timer += delta;
if (timer >= 20)
{
timer = 0;
ySpeed += .02f;
}[/code]
This gets called every time the player updates and delta is the time since the last update that slick provides. Originally it just added .02f to its speed every tick, but then I ran the game on my desktop and his speed increases to fast. Delta on my desktop is consistently 10, while delta on my laptop was 16-17. So update gets called faster. So I added this to keep it in check.
Now this works fine, but my question is, what if someones computer is so slow that delta is always say 30 on that machine? Then the player might fall noticeably slower. Technically the player falls slower on my laptop then my desktop, but the difference in minimal. So how do I get around this?
I know to move the player like this:
[code]xPos += xSpeed * delta;[/code]
So its the same across all systems, but I dont see how I would do something like that in cases like falling here.[/QUOTE]
Try changing ySpeed by delta * 0.2f (or similar) instead of using an accumulator ('timer'). Or, each time the accumulator...well, accumulates enough, you could subtract 20 from it instead of resetting it to 0. This means that if delta was 39, it would reset while still holding on to the extra 19 for the next tick.
Can anyone help me with sigscanning? I know (somewhat, I think I might be doing it wrong) how to find a function with Ida and get its signature, mask, and size, but I am kind of confused about how you would reverse the parameters of the function. I am also confused on how one would use the function once you found its address.
Thanks!
edit:
Oh yes, and before I forget, I have read [URL="http://wiki.alliedmods.net/Signature_Scanning"]this page[/URL].
[QUOTE=ArgvCompany;37771533]If you insist on a hierarchial system, just make a render class for each entity that needs it, and make it implement some generic interface. I do suggest though, that you use a component-based entityt system instead.[/QUOTE]
Wasn't there some example of a component-based entity system here or in WAYWO some time ago?
[QUOTE=esalaka;37773169]Wasn't there some example of a component-based entity system here or in WAYWO some time ago?[/QUOTE]
This one?
[QUOTE=SupahVee;36960152][URL]https://github.com/SuperV1234/VeeEntitySystem2012[/URL][/QUOTE]
One in C++ I think
[editline]23rd September 2012[/editline]
and not on github
[QUOTE=esalaka;37773812]One in C++ I think
[editline]23rd September 2012[/editline]
and not on github[/QUOTE]
[url]http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1/[/url]
?
[QUOTE=T3hGamerDK;37773872][url]http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1/[/url]
?[/QUOTE]
Not this either but this is more useful than the one I thought of. Thanks!
[QUOTE=esalaka;37773812]One in C++ I think
[editline]23rd September 2012[/editline]
and not on github[/QUOTE]
There is [URL="http://gamadu.com/artemis/"]Artemis[/URL], but it's Java.
[QUOTE=Eudoxia;37775008]There is [URL="http://gamadu.com/artemis/"]Artemis[/URL], but it's Java.[/QUOTE]
This was actually the one I looked for, which links to the link I posted.
You are actually looking for Cistron ([url]http://code.google.com/p/cistron/[/url]), it's better than artemis.
Can anyone give me suggestions for an animation system using spritesheets in SFML?
[QUOTE=chaoselite;37779349]Can anyone give me suggestions for an animation system using spritesheets in SFML?[/QUOTE]
Suggestions? I don't quite get what you're asking for.
[QUOTE=BMCHa;37780877]Suggestions? I don't quite get what you're asking for.[/QUOTE]
I'm not really sure how to go about implementing an animation system.
[QUOTE=chaoselite;37783583]I'm not really sure how to go about implementing an animation system.[/QUOTE]
1) get a "frames per second" variable and calculate the amount of time each frame should stay (1/fps)
2) keep track of the game time and accumulate how much time has passed.
3) if the accumulated time is greater than the framerate, set the texture of the object to the next frame and reset the accumulated time to 0.
[QUOTE=robmaister12;37785838]1) get a "frames per second" variable and calculate the amount of time each frame should stay (1/fps)
2) keep track of the game time and accumulate how much time has passed.
3) if the accumulated time is greater than the framerate, set the texture of the object to the next frame and reset the accumulated time to 0.[/QUOTE]
The way I was doing it was over complicating it a lot. It was essentially is that, except with a container holding frame variables and switch statements. Thanks!
I've got an on-screen compass that the player can click on. The ship rotates to face the point they clicked, using this code:
[lua]
float rotationAmount = delta/10f;
//rotationTarget is the degree difference between the ship's current facing and the facing they clicked
//rotation is the ship's current rotation
if (rotation < rotationTarget)
rotation += rotationAmount;
else if (rotation > rotationTarget)
rotation -= rotationAmount;
//this bit stops the ship from freaking out once it reaches the target
if (Math.abs(rotationTarget - rotation) < 1)
rotationTarget = rotation;
[/lua]
The problem is that if the ship is facing, for example, a rotation of 4 degrees (here on the left side of the circle because everything is rotated by -90), and the player clicks a rotationTarget of 340, the ship rotates in the wrong direction. It still reaches the target, but it goes the long way round.
Illustration:
[IMG]http://i.imgur.com/qXIvk.gif[/IMG]
For some reason my brain refuses to comprehend the problem (I'm trying to quit caffeine). Is there a simple solution?
To get the shortest angle required to rotate a onto b:
[code]((180+b-a) % 360)-180[/code]
I'm sure you can figure out how to use this in your code.
[QUOTE=MakeR;37787044]To get the shortest angle required to rotate a onto b:
[code]((180+b-a) % 360)-180[/code]
I'm sure you can figure out how to use this in your code.[/QUOTE]
Thanks! I'll try and wring a few more lines out of my brain before I pass out.
[editline]24th September 2012[/editline]
okay, got it.
What would be the best C++ cross-platform multimedia library?
I used SDL already, but it feels kind of odd and outdated. I thought about looking into SFML, but I first wanted to know what you guys think.
[QUOTE=marvinelo;37787351]What would be the best C++ cross-platform multimedia library?
I used SDL already, but it feels kind of odd and outdated. I thought about looking into SFML, but I first wanted to know what you guys think.[/QUOTE]
Both are fine, SFML is much easier though.
The reason SDL feels outdated is because it's a C library, which is old and doesn't have OOP.
I'm trying to texture a rectangle with a repeating 32x32 image using Slick.
Here's the texture:
[quote][IMG]http://i.imgur.com/Nt2pe.png[/IMG][/quote]
This is what happens when I try graphics.texture(shape, image, false); where 'false' means 'do not stretch to fit'.
[IMG]http://i.imgur.com/mw7xm.gif[/IMG]
Anyone know what's going wrong here?
[editline]asf[/editline]
It was too stupid a problem so I rolled my own:
[IMG]http://i.imgur.com/aghVN.jpg[/IMG]
ok need some c++ homework help here
first heres my code:
[cpp]//Chapter 7: Array Exercise U1-06p gradeRep01.cpp
// Elliott 9/26/2012
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void getData(string[], string[], int[], int);
void calculateGrade(int[], char[], int);
void printResult(string[], string[], int[], char[], int);
int main()
{
const int NO_OF_STUDENTS = 4;
string studentFNames[NO_OF_STUDENTS];
string studentLNames[NO_OF_STUDENTS];
int testScores[NO_OF_STUDENTS];
char letterGrades[NO_OF_STUDENTS];
cout << "Project " << "<U1-06p>"
<< " prepared by " << "<Elliott >\n\n";
getData(studentFNames, studentLNames, testScores, NO_OF_STUDENTS);
calculateGrade(testScores, letterGrades, NO_OF_STUDENTS);
printResult(studentFNames, studentLNames, testScores, letterGrades, NO_OF_STUDENTS);
return 0;
}
void getData(string firstNames[], string lastNames[], int scores[], int listSize)
{
//the following arrays are used for test data
string fNameTest[4] = {"Humpty", "Jack", "Mary", "Jack"};
string lNameTest[4] = {"Dumpty", "Horner", "Lamb", "Sprat"};
int scoresTest[4] = {59, 88, 100, 75};
//use a suitable loop to populate the appropriate function parameters
//with values from the three initialized test arrays
int n;
for(n=0; n<listSize; n++)
{
firstNames[n] == fNameTest[n];
lastNames[n] == lNameTest[n];
scores[n] == scoresTest[n];
}
}
void calculateGrade(int scores[], char grades[], int listSize)
{
//use multiple choice selection statement to calculate each letter grade
//and assign the result to the appropriate array element
int n;
for(n=0; n<listSize; n++)
{
if (scores[n] >= 90)
grades[n] = 'A';
else if (scores[n] >= 80)
grades[n] = 'B';
else if (scores[n] >= 70)
grades[n] = 'C';
else if (scores[n] >= 0)
grades[n] = 'F';
}
}
void printResult(string firstNames[], string lastNames[], int scores[], char grades[], int listSize)
{
// display the (unformatted) output from the parallel arrays
cout << "Student Name Test Score Grade\n" << endl;
int n;
for(n=0; n<listSize; n++)
{
cout << firstNames[n] << ", " << lastNames[n] << " " << scores[n] << " " << grades[n] << endl;
}
}
[/cpp]
and here's my result:
[IMG]https://4stor.com/images/avxe.png[/IMG]
why do my strings end up blank? whats wrong here?
oh and the point of this is to teach me the basics of strings, so this is all about strings and functions
Well first of all, you're doing comparison when you should be doing assignment, for example:
firstNames[n] == fNameTest[n];
should be
firstNames[n] = fNameTest[n];
Sorry, you need to Log In to post a reply to this thread.