PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

how do I add a new class to PF or even just use it with PF

I am trying to get Handango automatic registration working within my game. Having tried various RPN expression evaluators (needed to process the RPN string required by Handango I cannot get any of them to work, either because they are too simple (but PF likes them) or they are OO code which I don't know how to plug in to PF.

I have an expression evaluator which works fine stand alone. It's based on a class
Code:

class wzparser
{
// Members
protected:
wzstack<wzoperator*> m_arroperators;
wzarray<wzelement*> m_arrelements;
long m_nLastError;
TCHAR m_cArgumentSeparator;

// Construction
public:
wzparser();
virtual ~wzparser();

// Methods

// compiles a formula into byte-code
BOOL parse(LPSTR szFormula);

// eval a parsed formula (values being passed replace the variable placeholders)
BOOL eval(wzarray<wzvariable*> &arrVariables, wzstring &result);


// Accessors

void setArgumentSeparator(TCHAR c); // used between function arguments. Default is ';'
TCHAR getArgumentSeparator();

long getSize();
wzelement* get(long i); // ith element

long getLastError(); // valid if parse() returns FALSE
void dump(); // output content in the debug console

protected:
void free();
long add(wzelement* );

BOOL isOperator(/*in*/LPSTR* pp, /*out*/wzoperator** ppop);
BOOL isStringLitteral(/*in*/LPSTR pin, /*in*/LPSTR pout);

BOOL evalOperator(long &i, wzstring &result);
};


which is used in the code like this:-
Code:
wzparser* p = new wzparser();

but I don't know how to make this class work with PF. I have tried various things but obviously don't know enought C++ to make it work. Any clues would be welcome.

If I cannot get this to work I will just write a function to hard code the calculations needed.
Conan wrote:If I cannot get this to work I will just write a function to hard code the calculations needed.


This is probably a good idea. Keep this functionality it in a separate function. This way you don't create unecessary dependencies between PocketFrog and the registration code.

If you want to add it to your game class, say "MyGame', then simply declare it as a member:

Code:

class MyGame
{
//...
wszparser m_parser;
};


And then you can use it in any method. You don't need dynamic allocation (new) for this object.
Maybe I'm thinking too simplistically here, but why would you have to do anything at all? Why not just instantiate an instance of this class, use it, and discard it? I'm not seeing anything in the code that makes me think it needs to know whether it's running as part of a PF-based app or not.

Along the lines of what Thierry said, keep it a function, but if you have the class already and it works, why not just include it in your project and use it as-is?
Thanks Thierry & Frank, I know it all sounds simple to you guys & I'm sure you would laugh at the mistakes I make however it took me until a few minutes ago to get this building without errors. Now I have to see if it will evaluate the Handango RPN strings.

I started out by adding the code in pretty much as is with just the pf header & namespace being mentioned in the new source & the parser's .h's in my main .h where the game class lives but I kept getting errors. In the end by doing it the way Thierry suggested I was able to work through the errors & got it to build. My one & only class (Sprite) also helped as I used it to understand the new class.

ps: Once this works & my own reg code for non-Handango sales is in I need to spend a week (hopefully) killing these wierd PPC memory bugs & then I can beta test at long last.
Don't worry about those silly mistakes because (a) we all make them, whether we all admit to them or not, and (b) mistakes in programming are just about never silly anyway!

If you looked at the source for Invasion: Trivia you'd laugh your a** off... I could not for the life of me get my project to compile when I had various things in different .c or .cpp files, so what did I do?!? The entire project is a collection of HEADER files! Something like 50 of them I think, so the entire project is essentially one big global mess. Makes dealing with variable visibility a snap, but it's so absolutely the wrong way to structure a C project! Talk about something silly... Fortunately I figured it out doing K&G; Arcade, so that's put together in a more coherent manner (although even there it's not really right because most things are just members of the CGame class, so arguably it's only slightly better).

As my dad used to say... "Don't worry'bout it!"
The expression parser did not have an equal function (eg: if a==b then true) but had an extensible structure so I added an 'EQ' function and amazingly it returns the same values as the Handango RPN function so it looks like I can use it. It also has a few techniques which are new to me and a simple self contained string class so I'm glad I persevered.

update: the parser code had bugs so I just hard coded 12 lines to do the Handango reg code stuff. If only Handango had a sane example for developers I could have saved 2 days thinking it was hard when it was easy. No matter I will document for others.