You can use A*, just make areas into nodes(they should be equal in size) and the NPCs will just follow the nodes to their destination node.
Snip, wrong thread :v:
Hey guys, I need help with infix to prefix conversion, I understand the concept but I don't exactly know where to start out.
[QUOTE=evil-tedoz;34840506]Hey guys, I need help with infix to prefix conversion, I understand the concept but I don't exactly know where to start out.[/QUOTE]
For infix to RPN (postfix): [url]http://en.wikipedia.org/wiki/Shunting_yard_algorithm[/url]
I find that useful because RPN is easily parsed by a simple stack machine. You would probably be able to modify it a little bit to produce prefix, though.
So, I need some help guys..
I've made a resource manager, which scans a given folder and loads all the resources it can find. I also have a resource base class which have child classes for different kind of resources.
My resource manager contains a factory to create resource instances of the different types.
The problem I have is that when it finds a file, how does it know which kind of resource to instantiate?
You could try to look for the extension, as in : .txt, .png, etc.
[QUOTE=evil-tedoz;34841190]You could try to look for the extension, as in : .txt, .png, etc.[/QUOTE]
My first solution was to allow the user to map simple wildcard patterns to resource types, like a "*.png" maps to a ImageResource, but then you can also do more advanced stuff like "map*.png", which would perhaps map to a MapResource. But then "map01.png" would match both the "*.png" and "map*.png", so which one should it choose?
I'm not even sure I need that level of versatility :v:
[QUOTE=Z_guy;34841304]My first solution was to allow the user to map simple wildcard patterns to resource types, like a "*.png" maps to a ImageResource, but then you can also do more advanced stuff like "map*.png", which would perhaps map to a MapResource. But then "map01.png" would match both the "*.png" and "map*.png", so which one should it choose?
I'm not even sure I need that level of versatility :v:[/QUOTE]
Just use nongreedy matching - that way the wildcard in map*.png will match anything it can up to .png but it won't match the .png.
[QUOTE=Z_guy;34841056]The problem I have is that when it finds a file, how does it know which kind of resource to instantiate?[/QUOTE]
For every supported resource type, include a type checker in addition to the loader. For binary formats, it's usually as simple as checking the magic number and version numbers.
i.e.
[cpp]
bool isbsp(uint8_t *data, int n) {
if (n < 4) return false;
return data[0] == 'I' && data[1] == 'B' && data[2] == 'S' && data[3] == 'P';
}
[/cpp]
Then you do:
[cpp]
if (isbsp(data, n))
return loadbsp(data, n);
if (ispng(data, n))
return loadpng(data, n);
if (isjpg(data, n))
return loadjpg(data, n);
// etc...
[/cpp]
Of course it's a little more difficult for plaintext formats. At that point you pretty much have to guess by the extension/source. I've never been a fan of file extensions, though.
I wouldn't really go for wildcard-matching. I don't really have a good reason, it's just personal preference. I'd just split the last period-delimited substring off and check that against an extension string. IMHO, simpler, cleaner.
[QUOTE=ROBO_DONUT;34841742]For every supported resource type, include a type checker in addition to the loader. For binary formats, it's usually as simple as checking the magic number and version numbers.
i.e.
[cpp]
bool isbsp(uint8_t *data, int n) {
if (n < 4) return false;
return data[0] == 'I' && data[1] == 'B' && data[2] == 'S' && data[3] == 'P';
}
[/cpp]
Then you do:
[cpp]
if (isbsp(data, n))
return loadbsp(data, n);
if (ispng(data, n))
return loadpng(data, n);
if (isjpg(data, n))
return loadjpg(data, n);
// etc...
[/cpp]
Of course it's a little more difficult for plaintext formats. At that point you pretty much have to guess by the extension/source. I've never been a fan of file extensions, though.
I wouldn't really go for wildcard-matching. I don't really have a good reason, it's just personal preference. I'd just split the last period-delimited substring off and check that against an extension string. IMHO, simpler, cleaner.[/QUOTE]
Thank you, this was helpful, it got my cogs going again.
[QUOTE=shill le 2nd;34833466]Only value types (primitives and structs) get copied.[/QUOTE]
C# doesn't have any concept of 'primitives'
[QUOTE=Jimbomcb;34839407]The traces are being masked perfectly fine, I managed to find some of the engine level tracing stuff (from the hl2 leak by chance) and Lord Ned was right, it doesn't bother searching for hitboxes because it was using the bbox as a faster pre-pass test. Managed to work around it anyway.[/QUOTE]
You'll find that there are a decent number of things with Source that are like this. You're best keeping an extracted copy of the leak for reference; I do and it helps a lot.
Glad you found out the issue.
What does it mean to "return f( x, y, z )" as opposed to "return n" in a function, in C++, whereas f is a function?
[QUOTE=Flubadoo;34846025]What does it mean to "return f( x, y, z )" as opposed to "return n" in a function, in C++, whereas f is a function?[/QUOTE]
It means return whatever the function f(x, y, z) returns
So it runs the function f inside of the function where return f(x, y, z) was located?
Any idea why this snippet of C code makes me unable to type anything in the console?
[cpp]
char opt;
do
{
opt = getchar();
} while (opt != 'e')
[/cpp]
why are you storing getchar in a char
Fixed it, never mind. Didn't freeze - it just took a while the first time I ran the program which is weird.
[quote=esalaka]why are you storing getchar in a char[/quote]I omitted the other code that comes in after "opt = getchar()" in the loop because it wasn't relevant to the problem.
opt should still be an int.
You can use char if you don't care about EOFs.
[QUOTE=ROBO_DONUT;34851305]You can use char if you don't care about EOFs.[/QUOTE]
Wouldn't char break other non-ASCII codes as well?
[CODE]#include <iostream>
#include <cstdlib>
#include <string.h>
#include <stack>
using namespace std;
int OperatorHierarchy(char op)
{
int p;
switch (op)
{
case '+' :
case '-' :
p = 1;
break;
case '*' :
case '/' :
p = 2;
break;
default:
p = 0;
break;
}
return p;
}
int main()
{
//Infixe : 2*3/(2-1)+5*(4-1)
//Prefixe : +/*23-21*5-41
char ar[100];
stack<char> OutputStack, OperatorStack;
cin >> ar;
int length = strlen(ar);
// While input expression still remains, read and process the next token.
for(int i = length-1; i >= 0; i--)
{
switch(ar[i])
{
case '+':
case '-':
case '*':
case '/':
// If it is an operator, then
// i) If stack is empty, push operator on stack.
// ii) If the top of stack is closing parenthesis, push operator on stack.
// iii) If it has same or higher priority than the top of stack, push operator on stack.
// iv) Else pop the operator from the stack and add it to output string, repeat step 5.
if(OperatorStack.empty() || OperatorStack.top()==')' || OperatorHierarchy(ar[i]) >= OperatorHierarchy(OperatorStack.top()) )
{
OperatorStack.push(ar[i]);
}
else
{
OutputStack.push(OperatorStack.top());
OperatorStack.pop();
OperatorStack.push(ar[i]);
}
break;
case '(':
//If it is a opening parenthesis, pop operators from stack and add them to output string until a closing parenthesis is encountered. Pop and discard the closing parenthesis.
while(OperatorStack.top() != ')')
{
OutputStack.push(OperatorStack.top());
OperatorStack.pop();
}
OperatorStack.pop();
break;
case ')':
//If it is Closing parenthesis, push it on stack.
OperatorStack.push(ar[i]);
break;
default:
//If it is an operand, output it.
OutputStack.push(ar[i]);
break;
}
}
//If there is no more input, unstack the remaining operators and add them to output string.
while(!OperatorStack.empty())
{
if(OperatorStack.top() == '(' || OperatorStack.top() == ')')
{
cout << OperatorStack.top() << endl;
}
else
{
OutputStack.push(OperatorStack.top());
}
OperatorStack.pop();
}
//Display prefix output
while(!OutputStack.empty())
{
cout << OutputStack.top();
OutputStack.pop();
}
system("pause");
}
[/CODE]
This is my code to convert from infix to prefix, if anybody is interested.
[QUOTE=calzoneman;34851952]Wouldn't char break other non-ASCII codes as well?[/QUOTE]
I'm pretty sure it only grabs the next byte. C has no knowledge of character encodings. If you need wide characters for some reason, you'd have to do two consecutive getchar() calls anyway.
AFAIK, the only reason it returns int is because returning a negative value to indicate errors is a common paradigm in C (which does not support exceptions or multiple return values).
Or getwchar() or however it's called
Here:
[url]http://pubs.opengroup.org/onlinepubs/007904875/functions/fgetc.html[/url]
"Since fgetc() operates on bytes, reading a character consisting of multiple bytes (or "a multi-byte character") may require multiple calls to fgetc()."
getc() and getchar() function similarly.
[QUOTE=ROBO_DONUT;34852212]I'm pretty sure it only grabs the next byte. C has no knowledge of character encodings. If you need wide characters for some reason, you'd have to do two consecutive getchar() calls anyway.
AFAIK, the only reason it returns int is because returning a negative value to indicate errors is a common paradigm in C (which does not support exceptions or multiple return values).[/QUOTE]
It's also a very simple way of indicating errors since strings are usually considered to consist of unsigned chars.
Java after C++ makes so little sense. What do I use to store an array of things? In C++ you either use vector for random access or list for double linked shit, but now people are saying either use arraylist or just a simple array or list or what jesus. So what would I use to store primitives like integers and booleans, for things like strings, and for classes? And why is this wrong:
[code]List<Integer> lists = new List<Integer>();[/code]
How do you times a string by 100 my string is age and I want to make my program say it like:
Console.WriteLine("age* 100"); or something is that close?
[QUOTE=IndieGamer;34852866]How do you times a string by 100 my string is age and I want to make my program say it like:
Console.WriteLine("age* 100"); or something is that close?[/QUOTE]
What language? C#? You need to parse the string to an integer value, then multiply that by 100, and write it to the console.
[QUOTE=IndieGamer;34852866]How do you times a string by 100 my string is age and I want to make my program say it like:
Console.WriteLine("age* 100"); or something is that close?[/QUOTE]
Use a for loop that iterates 100 times
Sorry, you need to Log In to post a reply to this thread.