Learn C++ and Torque
by practicing01 · in Torque 2D Beginner · 06/12/2014 (7:44 am) · 7 replies
ITT we might learn. Post C++ questions and T2D source questions.
Q1) What is an iterator?
github.com/GarageGames/Torque2D/blob/development/engine/source/2d/sceneobject/Sc...
Q1) What is an iterator?
github.com/GarageGames/Torque2D/blob/development/engine/source/2d/sceneobject/Sc...
#2
github.com/GarageGames/Torque2D/blob/master/engine/source/2d/sceneobject/SceneOb...
06/16/2014 (7:52 am)
Q2) What are vectors? Can they be used for any object? An example would be nice.github.com/GarageGames/Torque2D/blob/master/engine/source/2d/sceneobject/SceneOb...
#3
More technically, it's an "array manager" which you can add objects to with either "pushFront" or "pushBack". Whenever the array is filled up, it creates a new array twice the size of the old array and copies the elements of the old array into the new array.
This way you don't have to worry about whether you've allocated enough space in your array.
It also makes it easier to insert objects in the middle of the array or remove objects inside the array with the "insert" and "erase" methods.
Lastly it can also behave like a stack with the "push" and "pop" methods.
06/16/2014 (9:01 am)
A2) Vectors are similar to lists in C# or Java.More technically, it's an "array manager" which you can add objects to with either "pushFront" or "pushBack". Whenever the array is filled up, it creates a new array twice the size of the old array and copies the elements of the old array into the new array.
This way you don't have to worry about whether you've allocated enough space in your array.
It also makes it easier to insert objects in the middle of the array or remove objects inside the array with the "insert" and "erase" methods.
Lastly it can also behave like a stack with the "push" and "pop" methods.
#4
07/18/2014 (3:08 pm)
This error is driving me nuts. Xcode keeps telling me "Expected class name" for public ImageFrameProvider. It's included in the header, so I'm not sure why the compiler can't find it?#ifndef _TEST_H_
#define _TEST_H_
#ifndef _BEHAVIOR_COMPONENT_H_
#include "component/behaviors/behaviorComponent.h"
#endif
#ifndef _IMAGE_FRAME_PROVIDER_H
#include "2d/core/ImageFrameProvider.h"
#endif
#ifndef _VECTOR2_H_
#include "2d/core/Vector2.h"
#endif
//-----------------------------------------------------------------------------
class Test : public BehaviorComponent, public ImageFrameProvider
{
private:
typedef BehaviorComponent Parent;
#5
07/18/2014 (3:12 pm)
Get the same error in VS or Appcode?
#6
07/18/2014 (5:57 pm)
Maybe it thinks it's an "incomplete type?" Perhaps you need to "pre-declare" that class in the file. I'm not entirely sure - I get weird things like this all the time on my little work tools projects and it's usually some obscure C++ rule making fun of me....
#7
GuiSpriteCtrl -> include GuiControl, ImageFrameProvider
ImageFrameProviderCore -> include GuiControl
That is ok, but:
NewClass -> include BehaviorComponent, ImageFrameProvider
ImageFrameProviderCore -> include NewClass
won't work.
07/19/2014 (5:31 am)
Ok, I figured out the issue. I was using GuiSpriteCtrl as an example and I had added an include to the new class in ImageFrameProviderCore. Getting rid of the circular dependency solved the compiler error.GuiSpriteCtrl -> include GuiControl, ImageFrameProvider
ImageFrameProviderCore -> include GuiControl
That is ok, but:
NewClass -> include BehaviorComponent, ImageFrameProvider
ImageFrameProviderCore -> include NewClass
won't work.
Torque Owner Lukas Joergensen
WinterLeaf Entertainment
It's based on the Iterator Pattern, a common pattern among object oriented design.
Edit: To clarify on the T2D implementation:
Returns a pointer to the first element in the list.
Returns a pointer to the last element in the list.
Is equivalent to the "next" method in the iterator pattern.
It would seem that the T2D version of the iterator is actually not a correct implementation of the iterator pattern but rather just a way of masking what actually happens. In T2D it works just like if you were dealing with an array, you got a pointer to an object incrementing that pointer gives you the next object in the list.