Game Development Community

Problem with processTick

by Hugo Mardolcar · in Torque Game Engine · 11/26/2003 (3:36 am) · 7 replies

Hello ppl

I'm trying to create a class to implement a real-world time notion (minutes, hours, days, etc)

My objective is to make this class singleton (so that there's 1 instance only).

But that's not the problem. The problem is that, despite my efforts, the processTick() method is never called.

I made the class a subclass of GameBase, I even tried making the class a subclass of player (just to test if the processTick would be called or not), but nothing works...

Right now I'm trying with a simple, test class, and not even that works... so please take a look and tell me what's wrong...

my test class:

teste.h
#ifndef _TESTE_H_
#define _TESTE_H_

#include "game/gameBase.h"

class teste : public GameBase
{
	typedef GameBase Parent;
public:
	teste();
	~teste();
	void processTick(const Move *move);
private:
	int a;
};

#endif

teste.cc
#include "game/lostages/teste.h"

teste::teste()
{
	a = 1;
	setProcessTick(true);
}

teste::~teste()
{
}

void teste::processTick(const Move* move)
{
	int a = 2;
        Con::printf("I'm processing the tick!!! yay!!");
}

#1
11/26/2003 (3:50 am)
Hugo,

You must register the gameBase object to receive 'ticks'. Do this by adding the following in your 'onAdd' function...
bool teste::onAdd()
{
	// Do Parent.
	if(!Parent::onAdd()) return(false);

	// Add to Scene.
	addToScene();

	// Start Tick Processing.
	[b]setProcessTick( true );[/b]
	
	// Return Okay.
	return true;
}

Be aware that this routine is called only every 32ms. Its cousin 'advanceTime' is called every frame although it is only called on the client.

Perhaps you should look at making a call into the platform layer with:
void Platform::getLocalTime(LocalTime &lt)

Hope this helps. :)

- Melv.
#2
11/26/2003 (4:03 am)
I'm going to try it, thanks!
#3
11/26/2003 (4:11 am)
Nope, it doesn't work...

the onAdd method is not even called...

I'm doing something wrong somewhere...

I'm creating the instance of this class when I drop a bot into the world (in the constructor of the bot class)

Do I need to do something else? Do I need the DECLARE_CONOBJECT and IMPLEMENT_CO_NETOBJECT_V1?
#4
11/26/2003 (4:21 am)
Hugo,

The gameBase class is quite a complex beast. I'd assumed that you'd implemented the rest of the required code. You are correct in that you need to put the macros you described into the class.

Not only that but the class is designed to run with an associated datablock e.g. something inherited from 'GameBaseData' which you need to setup. One of the more simpler examples of this setup within the engine is within MissionMarker.cc/.h'.

You should be getting console warnings or something though at the moment to indicate the object creation failure.

Also, adding objects such as these in the constructors of other objects may not be such a good idea. It might be wise to do it elsewhere such as in 'onAdd' functions.

- Melv.
#5
11/26/2003 (4:41 am)
Also, if you dont define a datablock when the object is created in scripts, i think the onAdd will fail (when the gamebase version is called through Parent::onAdd() ).
#6
11/26/2003 (9:26 am)
Oki dokie, thanks
#7
11/29/2003 (11:31 am)
And you have to register the object with the sim, too. The simplest way to get the object created in-game is to use the scripting language and say...

$foo = new myObject();

Which will instantiate and register the object.