The initial problem was solved. Please read down to third post for current problem. --TIA
Printable View
The initial problem was solved. Please read down to third post for current problem. --TIA
you can't have a variable name the same name as the class name -- tile is used both as the name of an unsigned int variable in the class constructor and a class.
Ok, that was the problem :D
However, now something much deeper and more evil seems to be afoot.
Now it says
[Linker error] undefined reference to `vtable for visual'
Oh boy, I have a feeling this isn't something small...
Attempting to create the object and assign it to a pointer via New is the line that causes the linker to give me the error.Code:extern HGE * hge;
/*
visual.DrawTile
visual.DrawText
visual.DrawLine
visual.Draw
*/
class visual
{
public:
// Simple constructor for a new Visual
visual(float location_z, float location_x,float location_y,unsigned int color)
{
this->location_z=location_z;this->location_z=location_x;this->location_z=location_y;this->color=color;
};
virtual void render(void);// Base function for Visual render. Will be filled in in subclasses
static void DrawTile(float,float,float,unsigned int,unsigned int,unsigned char,hgeQuad *);// Make a Tile for this frame
static void Draw(void);// Run the render in full and purge the list
protected:
static visual * root; // Root pointer for rendering list
visual * next_visual; // Pointer to next visual
float location_z,location_x,location_y;// XY and Z location for Visual
unsigned int color; //Color value for Visual 0xAARRGGBB
};
visual * visual :: root = 0; // Making sure root pointer is null to begin with
class tile : public visual
{
public:
//Constructor for a tile, that passes the needed values to the base class
tile(float location_z,float location_x,float location_y,unsigned int color,unsigned int tile_number,unsigned char blend,hgeQuad * quad) :
visual(location_z,location_x,location_y,color)
{
this->tile_number = tile_number;
};
protected:
void render(void);
unsigned int tile_number;
unsigned char blend;
hgeQuad * quad;
};
//The actual Tile render routine, meant to supplant RenderQuad
void tile::render(void)
{
//Set all the values needed for this specific stamp.
for(int i=0;i<4;i++)
{
quad->v[i].z=1.0;
quad->v[i].col=color;
}
quad->v[0].tx=float(tile_number%39)*32.0/2048.0; quad->v[0].ty=float(tile_number/39)*32.0/2048.0;
quad->v[1].tx=float((tile_number%39)+1)*32.0/2048.0; quad->v[1].ty=float(tile_number/39)*32.0/2048.0;
quad->v[2].tx=float((tile_number%39)+1)*32.0/2048.0; quad->v[2].ty=float((tile_number/39)+1)*32.0/2048.0;
quad->v[3].tx=float(tile_number%39)*32.0/2048.0; quad->v[3].ty=float((tile_number/39)+1)*32.0/2048.0;
quad->v[0].x=location_x; quad->v[0].y=location_y;
quad->v[1].x=location_x+32; quad->v[1].y=location_y;
quad->v[2].x=location_x+32; quad->v[2].y=location_y+32;
quad->v[3].x=location_x; quad->v[3].y=location_y+32;
quad->blend=blend;
//Send to screen.
hge->Gfx_RenderQuad(quad);
}
//Function to create a tile for this frame
void visual::DrawTile(float location_z,float location_x,float location_y,unsigned int color,unsigned int tile_number,unsigned char blend,hgeQuad * quad)
{
visual * newbie = new tile(location_z,location_x,location_y,color,tile_number,blend,quad);
}
//Renderquad test function for member function used for Tiles
void RenderQuad(float x, float y, unsigned int tile, unsigned int color, unsigned char blend,hgeQuad * quad,HGE* hge)
{
//Set all the values needed for this specific stamp.
for(int i=0;i<4;i++)
{
quad->v[i].z=1.0;
quad->v[i].col=color;
}
quad->v[0].tx=float(tile%39)*32.0/2048.0; quad->v[0].ty=float(tile/39)*32.0/2048.0;
quad->v[1].tx=float((tile%39)+1)*32.0/2048.0; quad->v[1].ty=float(tile/39)*32.0/2048.0;
quad->v[2].tx=float((tile%39)+1)*32.0/2048.0; quad->v[2].ty=float((tile/39)+1)*32.0/2048.0;
quad->v[3].tx=float(tile%39)*32.0/2048.0; quad->v[3].ty=float((tile/39)+1)*32.0/2048.0;
quad->v[0].x=x; quad->v[0].y=y;
quad->v[1].x=x+32; quad->v[1].y=y;
quad->v[2].x=x+32; quad->v[2].y=y+32;
quad->v[3].x=x; quad->v[3].y=y+32;
quad->blend=blend;
//Send to screen.
hge->Gfx_RenderQuad(quad);
}
The compiler is looking for the implementation of visual::render()
Try this way:
or thatCode:virtual void render(void) = 0;// Base function for Visual render. Will be filled in in subclasses
KurtCode:virtual void render(void){};// Base function for Visual render. Will be filled in in subclasses
Edit: there might be more errors but I'm not able to read code without indentation.
Ah man, thanks guys. I really appreciate the help.
Sometimes it's so hard to find your own errors, especially as you are learning. That fixed it right up. In fact, I remember reading to do that exact thing.
Sorry about the indentations etc. I am sure there are more errors, I will improve the style to make future posts more tolerable.
By the way, how much of a readability improvement is this?
There are funky spaces appearing in the code when I paste it here.
Code://HGE engine instance pointer
extern HGE * hge;
/*
** The visual class is an abstract base class for all
** objects representing actual screen drawing.
**
**
*/
//==============================================================================
//= Visual Base Class =
//==============================================================================
class visual
{
public://*****************************************************************
// Make a Tile
static void DrawTile(float,float,float,unsigned int,unsigned int,unsigned char,hgeQuad *);
// Draw all visuals
static void Draw(void);
//Constructor for visual
visual(float location_z, float location_x,float location_y,unsigned int color)
{
this->location_z=location_z;this->location_z=location_x;
this->location_z=location_y;this->color=color;
this->next_visual = 0;
};
// Base virtual function for rendering objects
virtual void render(void){};
protected://**************************************************************
// XY and Z location for Visual
float location_z,location_x,location_y;
//Color value for Visual 0xAARRGGBB
unsigned int color;
// Root pointer for rendering list
static visual * root;
// Pointer to next visual
visual * next_visual;
};
// Making sure root pointer is null to begin with
visual * visual :: root = 0;
//==============================================================================
//= tile subclass of visual : Represents a textured tile on screen =
//==============================================================================
class tile : public visual
{
public://*****************************************************************
//Constructor for tile
tile(float location_z,float location_x,float location_y,unsigned int color,unsigned int tile_number,unsigned char blend,hgeQuad * quad) :
visual(location_z,location_x,location_y,color)
{
this->tile_number = tile_number;
this->quad = quad;
this->blend = blend;
};
//Render function for tile
void render(void);
protected://**************************************************************
//Which of the tiles in the set will be used
unsigned int tile_number;
//Which style of blending will be used
unsigned char blend;
//Which quad will be used to stamp
hgeQuad * quad;
};
//Function to create a tile for this frame
void visual::DrawTile(float location_z,float location_x,float location_y,unsigned int color,unsigned int tile_number,unsigned char blend,hgeQuad * quad)
{
//Create a tile object and give to new_tile pointer
visual * new_tile = new tile(location_z,location_x,location_y,color,tile_number,blend,quad);
//If root is null root points to this tile and it points to null
if(root = 0)
{
root = new_tile;
new_tile->next_visual=0;
}
//Otherwise it will have to be placed in order
else
{
// ADD CODE HERE for: Placing in ordered list
};
}
//The tile specific render routine
void tile::render(void)
{
//Set all the values needed for this specific stamp.
for(int i=0;i<4;i++)
{
//I don't use internal Z so I just set it to 1 for all verts.
quad->v[i].z=1.0;
//I don't need individually shaded verts so I set all to color value.
quad->v[i].col=color;
}
//Sets the texture location to use via tile from root image.
quad->v[0].tx=float(tile_number%39)*32.0/2048.0; quad->v[0].ty=float(tile_number/39)*32.0/2048.0;
quad->v[1].tx=float((tile_number%39)+1)*32.0/2048.0; quad->v[1].ty=float(tile_number/39)*32.0/2048.0;
quad->v[2].tx=float((tile_number%39)+1)*32.0/2048.0; quad->v[2].ty=float((tile_number/39)+1)*32.0/2048.0;
quad->v[3].tx=float(tile_number%39)*32.0/2048.0; quad->v[3].ty=float((tile_number/39)+1)*32.0/2048.0;
//Sets quads according to screen location desired.
quad->v[0].x=location_x; quad->v[0].y=location_y;
quad->v[1].x=location_x+32; quad->v[1].y=location_y;
quad->v[2].x=location_x+32; quad->v[2].y=location_y+32;
quad->v[3].x=location_x; quad->v[3].y=location_y+32;
quad->blend=blend;
//Send to screen.
hge->Gfx_RenderQuad(quad);
}
This is a lot better. :)
You should just add a few blank lines ( hope you haven't only to save space in the forum )
Kurt