I am learning to use SDL and I just got around to making a tile engine however the amount of tiles I want to use is 256x256 but it gets REALLY slow when the whole screen if filled with tiles. Does anybody know a good tutorial on making a optimized tile engine? Or should I just try and use SDL in combination with OpenGL?
I fixed GWEN to work with the latest SFML version and got a canvas with a button working but so far the button does nothing. I tried to add an event using this code:
[CODE]Gwen::Controls::Button* pButton = new Gwen::Controls::Button( pCanvas );
pButton->SetBounds( 10, 10, 100, 50 );
pButton->SetText( "Exit" );
pButton->onPress.Add (pButton , &OnQuit);[/CODE]
but it would give me this error:
[quote]/usr/include/Gwen/Events.h: In instantiation of ‘void Gwen::Event::Caller::Add(Gwen::Event::Handler*, T) [with T = void (*)(Gwen::Controls::Base*)]’:
/home/bumrang/gwen/main.cpp:50:44: required from here
/usr/include/Gwen/Events.h:127:65: error: invalid static_cast from type ‘void (*)(Gwen::Controls::Base*)’ to type ‘Gwen::Event::Handler::Function {aka void (Gwen::Event::Handler::*)(Gwen::Controls::Base*)}’
[/quote]
What should "&OnQuit" be? Right now all it does is quit the program.
Also what should in the arguments for onPress.Add? I'm not sure what pButton is for.
This is my first time using GWEN, so I'm still working around it.
When you are drawing a triangle mesh that have a variable number of other vertices linked to each other do you want to use a simple array of ints (not connected) or an array of pointers? I am coding in java so I would need to make a vertex class to hold the int.
In C++, I have a class that takes two ints for its constructor. I want to create a derived class that takes a filename for its constructor and reads that file to get the parameters for the base class.
What is the proper way to do this? I need lots of logic for the file opening/closing, but I need the arguments for the base class in the initializer list.
I have a problem with my Tile engine in sdl. When the screen is filled with about 400 tiles my fps gets really low (about 30fps). If I draw everything without an alpha channel I get a capped 60fps.
[cpp]
#include "stdafx.h"
#include <string>
#include <SDL.h>
#include <vector>
#include "Define.h"
#include "CDraw.h"
#include "CTile.h"
#include "CArea.h"
#include "CCamera.h"
SDL_Surface *flattile = NULL;
SDL_Surface *screen = NULL;
SDL_Event event;
CCamera Camera;
void drawraisedtile(int i,int o);
int main( int argc, char* args[] )
{
std::vector<CArea> AreaList; // Create a vector for all the areas
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(WWIDTH, WHEIGHT, 0, 0);
flattile = SDL_LoadBMP("tileflat.bmp");
Uint32 colorkey = SDL_MapRGB( flattile->format, 0xFF, 0xFF, 0xFF ); //Create the colorkey for flattile
SDL_SetColorKey( flattile, SDL_SRCCOLORKEY, colorkey ); //Apply the color key
for(int i = 0;i < 1; i++) // Create all the areas
{
CArea tempArea;
tempArea.buildArea();
AreaList.push_back(tempArea);
}
bool quit = false;
while( quit == false )
{
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
{
quit = true;
}
}
switch(event.type) // switch to move the camera around
{
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_a:
Camera.x = Camera.x+3;
break;
case SDLK_d:
Camera.x = Camera.x-3;
break;
case SDLK_w:
Camera.y = Camera.y+3;
break;
case SDLK_s:
Camera.y = Camera.y-3;
break;
}
}
for(int i = 0; i < AreaList.size(); i++) // Draw every Tilelist
{
AreaList[i].drawArea(screen, flattile, Camera);
}
SDL_Flip(screen);
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0, 0, 0)); // Fill the screen black
}
SDL_Quit();
return 0;
}
[/cpp]
and here is the CArea.cpp
[cpp]
#include "stdafx.h"
#include "CArea.h"
#include "CTile.h"
void CArea::buildArea() // Fill a TileList with the apropriate x and y values
{
for(int i = 0;i < 100; i++)
{
for(int o = 100;o > 0; o--)
{
CTile tempTile;
tempTile.x = (32*o)+(32*i);
tempTile.y = (WHEIGHT/2-(16*i))+(o*-16)+(i*32);
TileList.push_back(tempTile);
}
}
}
void CArea::drawArea(SDL_Surface *screen, SDL_Surface *flattile, CCamera camera)
{
for(int i = 0;i < TileList.size(); i++) // Draw a Tile
{
SDL_Rect Tile = {TileList[i].x+camera.x, TileList[i].y+camera.y, WWIDTH, WHEIGHT};
SDL_BlitSurface(flattile, NULL, screen, &Tile);
}
}
[/cpp]
I'm assuming I'm doing something horribly wrong because I'm pretty sure it shouldn't be so slow.
Excuse me if my code is a horrible mess.
I don't really know python. I'm trying to see the function names in a .pyd file by importing it but the file I'm trying to import is named like enet.enet.pyd for example. If I import enet.enet I get "ImportError: No module named enet.enet" But If I rename it to enetenet.pyd I get "ImportError: dynamic module does not define init function (initenetenet)"
[QUOTE=sparky28000;38955288]I have a problem with my Tile engine in sdl. When the screen is filled with about 400 tiles my fps gets really low (about 30fps). If I draw everything without an alpha channel I get a capped 60fps.
[cpp]
#include "stdafx.h"
#include <string>
#include <SDL.h>
#include <vector>
#include "Define.h"
#include "CDraw.h"
#include "CTile.h"
#include "CArea.h"
#include "CCamera.h"
SDL_Surface *flattile = NULL;
SDL_Surface *screen = NULL;
SDL_Event event;
CCamera Camera;
void drawraisedtile(int i,int o);
int main( int argc, char* args[] )
{
std::vector<CArea> AreaList; // Create a vector for all the areas
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(WWIDTH, WHEIGHT, 0, 0);
flattile = SDL_LoadBMP("tileflat.bmp");
Uint32 colorkey = SDL_MapRGB( flattile->format, 0xFF, 0xFF, 0xFF ); //Create the colorkey for flattile
SDL_SetColorKey( flattile, SDL_SRCCOLORKEY, colorkey ); //Apply the color key
for(int i = 0;i < 1; i++) // Create all the areas
{
CArea tempArea;
tempArea.buildArea();
AreaList.push_back(tempArea);
}
bool quit = false;
while( quit == false )
{
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
{
quit = true;
}
}
switch(event.type) // switch to move the camera around
{
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_a:
Camera.x = Camera.x+3;
break;
case SDLK_d:
Camera.x = Camera.x-3;
break;
case SDLK_w:
Camera.y = Camera.y+3;
break;
case SDLK_s:
Camera.y = Camera.y-3;
break;
}
}
for(int i = 0; i < AreaList.size(); i++) // Draw every Tilelist
{
AreaList[i].drawArea(screen, flattile, Camera);
}
SDL_Flip(screen);
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0, 0, 0)); // Fill the screen black
}
SDL_Quit();
return 0;
}
[/cpp]
and here is the CArea.cpp
[cpp]
#include "stdafx.h"
#include "CArea.h"
#include "CTile.h"
void CArea::buildArea() // Fill a TileList with the apropriate x and y values
{
for(int i = 0;i < 100; i++)
{
for(int o = 100;o > 0; o--)
{
CTile tempTile;
tempTile.x = (32*o)+(32*i);
tempTile.y = (WHEIGHT/2-(16*i))+(o*-16)+(i*32);
TileList.push_back(tempTile);
}
}
}
void CArea::drawArea(SDL_Surface *screen, SDL_Surface *flattile, CCamera camera)
{
for(int i = 0;i < TileList.size(); i++) // Draw a Tile
{
SDL_Rect Tile = {TileList[i].x+camera.x, TileList[i].y+camera.y, WWIDTH, WHEIGHT};
SDL_BlitSurface(flattile, NULL, screen, &Tile);
}
}
[/cpp]
I'm assuming I'm doing something horribly wrong because I'm pretty sure it shouldn't be so slow.
Excuse me if my code is a horrible mess.[/QUOTE]
Could you provide a complete project that's compilable?
[QUOTE=Jookia;38955637]Could you provide a complete project that's compilable?[/QUOTE]
Here you go. [url]http://www.solidfiles.com/d/07c6e0e9fe/[/url]
Sorry it took me so long.
How do you remove sources from Git/Bitbucket?
[QUOTE=sparky28000;38955288]I have a problem with my Tile engine in sdl. When the screen is filled with about 400 tiles my fps gets really low (about 30fps). If I draw everything without an alpha channel I get a capped 60fps.
//code
I'm assuming I'm doing something horribly wrong because I'm pretty sure it shouldn't be so slow.
Excuse me if my code is a horrible mess.[/QUOTE]
Try not drawing every single tile every frame.
Draw every tile to an SDL_Surface, and render only that surface every frame. When a tile needs an update, you simply re-render the tile to that surface. If tile movement/removal is a factor, re-render every tile. You can optimize this even further as well.
That way you don't have 400 render calls, but only one.
[QUOTE=AtomiCasd;38960415]Try not drawing every single tile every frame.
Draw every tile to an SDL_Surface, and render only that surface every frame. When a tile needs an update, you simply re-render the tile to that surface. If tile movement/removal is a factor, re-render every tile. You can optimize this even further as well.
That way you don't have 400 render calls, but only one.[/QUOTE]
If I move around on the screen I have to update every tile with a new x and y. Is there a way I can move the surface I blitted everything to around?
I forgot that in SDL you have to take care of those kind of stuff. Last time I used SDL was in 2007. I can't remember the function calls so I'm sorry, you should check out some of the tutorials on google like [url]http://www.sdltutorials.com/[/url]
A short answer would be to point you in the dirction of [url=www.sfml-dev.org]SFML[/url] because it handles these kind of things internally (you move your view around).
For example, [url]http://sfml-dev.org/documentation/2.0/classsf_1_1View.php[/url]. Think of it like the camera.
[QUOTE=AtomiCasd;38960906]I forgot that in SDL you have to take care of those kind of stuff. Last time I used SDL was in 2007. I can't remember the function calls so I'm sorry, you should check out some of the tutorials on google like [url]http://www.sdltutorials.com/[/url]
A short answer would be to point you in the dirction of [url=www.sfml-dev.org]SFML[/url] because it handles these kind of things internally (you move your view around).
For example, [url]http://sfml-dev.org/documentation/2.0/classsf_1_1View.php[/url]. Think of it like the camera.[/QUOTE]
I will try sfml tomorow. I can't wrap my head around SDL at the moment. Thank you!
[editline]24th December 2012[/editline]
Do you recommend using 2.0 or 1.6?
2.0, since 1.6 is basically outdated by now. I know for sure 1.6 doesn't work on some ATI cards.
SFML is easier to get into than SDL
[URL]http://www.sfml-dev.org/documentation/2.0/[/URL] is the documentation for it, which is basically a good enough tutorial because it's really descriptive
[URL]http://sfml-dev.org/documentation/2.0/annotated.php[/URL]
List of classes
Snip, looks like I can't follow simple directions.
-snap-
Could anyone put in steps how the hell I can get MySQL working with C++? I tried googling it, tho I found nothing. I'm using Visual Studio 2010.
If you have access to a webserver, you could have a PHP script query the database and return the result to you.
[QUOTE=Persious;38969061]Could anyone put in steps how the hell I can get MySQL working with C++? I tried googling it, tho I found nothing. I'm using Visual Studio 2010.[/QUOTE]
I've never done it myself, but it seems that you need to install a connector on your computer first. It acts as a driver.
You can download them here: [url]http://www.mysql.com/downloads/connector/cpp/[/url]
To actually get working with it, I'd suggest you read the tutorial here:
[url]http://dev.mysql.com/tech-resources/articles/mysql-connector-cpp.html[/url]
It seems really in-depth and walks you through the entire process.
[QUOTE=Gulen;38969203]If you have access to a webserver, you could have a PHP script query the database and return the result to you.[/QUOTE]
That's not a solution, that's just a different problem.
[QUOTE=Dr Magnusson;38969341]
That's not a solution, that's just a different problem.[/QUOTE]
I look at it as a work-around. I've never been able to find anything concrete on it, iirc. And I was just giving him one way to solve it, he didn't necessarily have to do that.
[QUOTE=Gulen;38969392]I look at it as a work-around. I've never been able to find anything concrete on it, iirc. And I was just giving him one way to solve it, he didn't necessarily have to do that.[/QUOTE]
Sorry about the passive-aggressive response. It's just really common that people ask questions like "How do I do 3D programming using OpenGL in C++?" and someone answers "Do 2D programming with XNA using C#" :v:
Guys!
I'm trying to program a c++ code that uses the ansi.sys, but my Windows 7 does not have this fucking file!! Where I can download it? My computer, also, does not have the config.nt file. I need these files to let me continue to read my C++ book
[QUOTE=Cesar Augusto;38970549]Guys!
I'm trying to program a c++ code that uses the ansi.sys, but my Windows 7 does not have this fucking file!! Where I can download it? My computer, also, does not have the config.nt file. I need these files to let me continue to read my C++ book[/QUOTE]
What book?
[QUOTE=Larikang;38952084]In C++, I have a class that takes two ints for its constructor. I want to create a derived class that takes a filename for its constructor and reads that file to get the parameters for the base class.
What is the proper way to do this? I need lots of logic for the file opening/closing, but I need the arguments for the base class in the initializer list.[/QUOTE]
Still trying to figure this out.
Also, in GDB, I have a function that throws an exception sometimes, but gets called many times a second. What I would like to do is examine the program state of the functions that call that function when it throws an exception. Is there a way to change the GDB context to another point in the backtrace?
Ok...I know it's funny but I'm having some troubles here. Please, just help me. :)
[QUOTE=Larikang;38972220]Still trying to figure this out.
Also, in GDB, I have a function that throws an exception sometimes, but gets called many times a second. What I would like to do is examine the program state of the functions that call that function when it throws an exception. Is there a way to change the GDB context to another point in the backtrace?[/QUOTE]
Yes. 'frame #', where you replace # with the number from 'backtrace'.
[QUOTE=Cesar Augusto;38973209]Ok...I know it's funny but I'm having some troubles here. Please, just help me. :)[/QUOTE]
if you want help you might want to stop ignoring people who are trying to help you
[QUOTE=dajoh;38974170]if you want help you might want to stop ignoring people who are trying to help you[/QUOTE]
I'm not ignoring, sorry.
[QUOTE=Asgard;38970910]What book?[/QUOTE]
It's a portuguese C++ book. I'm now in the functions chapter that show about this
[QUOTE=Larikang;38972220]Still trying to figure this out.
Also, in GDB, I have a function that throws an exception sometimes, but gets called many times a second. What I would like to do is examine the program state of the functions that call that function when it throws an exception. Is there a way to change the GDB context to another point in the backtrace?[/QUOTE]
I believe you can only refer to a base class constructor when you do
[code]DerivedClass() : BaseClass()
{
//Derived constructor code
}[/code]
So you cannot do it the way you want to do it. Your best bet would to not use a base constructor to set the two int values, why not just set it regularly in the constructor for the derived class? Unless those two ints are only relevant to the base class and don't appear in the derived class, then why not just use a function supplied in the base class to set the two values?
[QUOTE=Cesar Augusto;38974199]I'm not ignoring, sorry.
It's a portuguese C++ book. I'm now in the functions chapter that show about this[/QUOTE]
Get a new book. After reading about ansi.sys on wikipedia, it seems like a totally useless file (it adds some colours, macros and different video modes to CMD) It seems like the book should be able to teach you about functions without this file (mine did)
Sorry, you need to Log In to post a reply to this thread.