Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - crumpetxxix

Pages: [1]
1
System / Re: Multiple argument functioned thread
« on: September 04, 2012, 12:44:47 am »
Quote from: eXpl0it3r
I'm assuming you're refering to SFML 2.

I guess there are many ways to achive this.
Since you can declare which type you want to pass, you can create the type you want, so it could be your own struct or your own class or just an std::vector, etc...
Another way is to have the variable in the same scope (probably global scope in your case), which needs quite a bit more attetion so you don't run into race conditions. Also keep in mind global variables aren't such a nice code design. For the global scope problem you could make the function a member of a class and then use the member variables (you'll still have to make sure that there are no race conditions).
Yeah sorry i meant 2.0.  i think i might be able to do what i need with a new class or possibly a struct, ill check it out unless the std::bind works for what i need
The two easiest solutions are:

1. Use C++11 or boost or tr1
sf::Thread thread(std::bind(&f, a, b, c, d));

2. If you can't use anything of solution 1., then gather the four parameters into one
struct Params
{
    ...;
    ...;
    ...;
    ...;
};

Params p = {a, b, c, d};
sf::Thread thread(&f, p);
sorry im a bit of a novice programmer in c++ and using the sfml librarys, but im guessing the struct will just gather my 4 parameters into one so it would look something like
Code: [Select]
struct Param
{
    GamePlayer player;
    DBManager dbManager;
    CameraManager camManager;
};
then for the function im calling for the thread it would be
Code: [Select]
void TheThreadFunction(Param p)
{
    //code for thread belongs here
}
and finally the call to my thread would be  (within int main())
Code: [Select]
Param newParam {activePlayer, activeDBManager, activeCamera}
sf::Thread myThread(&TheThreadFunction, newParam);
myThread.launch();
where activePlayer, activeDBManager, and activeCamera are already set instances of GamePlayer, DBManager, and CameraManager

does this look right?

also what it looks like i just did there the std::bind looks like it basically took care of that for me.  Ill play around with it and see how either of those options work out.  Thank you

2
System / Multiple argument functioned thread
« on: September 03, 2012, 11:09:21 pm »
So with in sf::Thread you can only pass a thread through a function with no or just 1 argument.  For my game, I have a function which checks whether or not a new background tile needs to be loaded or not, then loads it.  Although this function requires four arguments.  So i know that i cant make this function into a thread so i was wondering how i would get around this limitation

3
General / Re: Adding a counter makes an access writing violation?
« on: August 31, 2012, 06:44:30 pm »
Fixed, i realized i shouldnt have initiliazed the yCnt = 0; above both loops and stuck it in between the loops so it would reset to 0 instead of becoming larger than my array size

4
General / Adding a counter makes an access writing violation?
« on: August 31, 2012, 05:57:02 pm »
Ok so this is more of a general help question versis sfml based but please hear me out because i couldnt find any solution for this online

In my game, the maps / movement are supposed to work like in pokemon where your character stays centered on the screen and the map moves around you, which is handeled by a camera manager holding which hold a cell which then hold the tiles and any object on the screen which needs to be moved when you move. Although that isnt the exact problem at the moment.  Because of how i want the game to be set up the map consists of 64x64 tiles which are linked together by a database and loaded into the game.  Fine so far, but here is the problem.  When im doing the initial load into my game which takes a double array of of tiles and puts them into the active camera cells i get an access read violation when i use a counter within the loop.. Let me show you instead of just sayinf my problem

Code: [Select]
int xCnt = 0, yCnt = 0;
for (int coordX = (thisPlayer.regionX - 5); coordX < (thisPlayer.regionX + 6); coordX++)
{
for (int coordY = (thisPlayer.regionY - 4); coordY < (thisPlayer.regionY + 5); coordY++)
{
theCam.activeCells[xCnt][yCnt].setLocalX(xCnt);
theCam.activeCells[xCnt][yCnt].setLocalY(yCnt);
if (!mnger.LoadTile(thisPlayer.regionID, coordX, coordY, theCam.activeCells[xCnt][yCnt].mTile))
{
return false;
}
if (theCam.activeCells[xCnt][yCnt].mTile.tileType == 1)
{
theCam.activeCells[xCnt][yCnt].mTile.tileTexture = grassBGImg;
}
else if (theCam.activeCells[xCnt][yCnt].mTile.tileType == 2)
{
theCam.activeCells[xCnt][yCnt].mTile.tileTexture = dirtBGImg;
}
else
{
theCam.activeCells[xCnt][yCnt].mTile.tileTexture = grassBGImg;
}
theCam.activeCells[xCnt][yCnt].mTile.tileSprite.setTexture(theCam.activeCells[xCnt][yCnt].mTile.tileTexture);
theCam.activeCells[xCnt][yCnt].mTile.tileSprite.setPosition(theCam.activeCells[xCnt][yCnt].getXPos(), theCam.activeCells[xCnt][yCnt].getYPos());
yCnt++;
}
xCnt++;
}
^ is the piece of code which is giving me the access writing violation, and the actual line which is giving me the error is
Code: [Select]
xCnt++;I cant understand for the life of me why this counter is breaking my game, please help

5
General / Re: [Help] Manipulating a string within a loop bug
« on: August 29, 2012, 08:29:58 pm »
Hmm, that was a good read.  I overlooked the find function because i had it confused with the find_first_of function so i never even gave it a second thought about using, that seems like it would have been a lot easier to use the find function instead of the loop checking every character one by one.  Thank you.

6
General / Re: [Help] Manipulating a string within a loop bug
« on: August 29, 2012, 05:10:12 pm »
Never mind im an idiot. i thought the substr function parameters were substr(startposition, endposition).. turns out its substr(startpos, numberofcharacters).  i dont know how i ended up getting the rest of my DB reader to work since its also using substr but i think this should fix it

7
General / [Help] Manipulating a string within a loop bug
« on: August 29, 2012, 02:58:47 pm »
Ok so im using SFML2.0 with visual studios 2008 if that helps at all.. In the process of creating my game I've come into a problem when using string.substr and i cant figure out for the hell of me why this is happening.
In the game I'm creating, like most other games you need to load from a database, simple enough.  So I started writing my database reader in my program and created a sample DB for my reader.  It opens, checks for the right DB and formatting, finds, and reads the lines and stores them into a dynamic array of strings for me to manipulate.. But when i actually get to the area where my actual data is I cannot get it to find the right line in my code to be able to decifer where the data is on the line..

If that didnt make enough sense let me show you. If within my database i had the line RegionID==1, i cant get my code to find the part of the string which has the "==" in it to seperate the data table with the data.

Within my code here is the segment where it takes one of the lines within the database which has been read, then it checks the string for the "==" and tries to read the data into the game

dataLine is the string with the data being read, break() is just a cout function to help me decifer whats breaking and the variable dataRep is the "==" which is supposed to be being found within the string

Code: [Select]
for (int cntr = 0; cntr < dataLine.length(); cntr++)
{
Break(8);
std::cout << dataLine.substr(cntr, cntr + 2) << std::endl;
std::cout << cntr << " " << cntr + 2 << std::endl;
if (dataLine.substr(cntr, cntr + 2) == dataRep)
{
if (dataLine.substr(0, cntr) == "Name")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setName(dataLine.substr(cntr + 2, dataLine.length()));
break;
}
if (dataLine.substr(0, cntr) == "RegID")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setRegionID(atoi(dataLine.substr(cntr + 2, dataLine.length()).c_str()));
break;
}
if (dataLine.substr(0, cntr) == "RegX")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setRegionX(atoi(dataLine.substr(cntr + 2, dataLine.length()).c_str()));
break;
}
if (dataLine.substr(0, cntr) == "RegY")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setRegionY(atoi(dataLine.substr(cntr + 2, dataLine.length()).c_str()));
break;
}
if (dataLine.substr(0, cntr) == "Direction")
{
//std::cout << dataLine.substr(cnt + 2, dataLine.length()) << std::endl;
player.setDirFacing(atoi(dataLine.substr(cntr + 2, dataLine.length()).c_str()));
break;
}
}
}

so as you can see from my code i had the console output what the actual sub string of what was currently being read and also between which two numbers in the code.  The actual numbers i printed within the loop are normal but here is what the substr output reads.

if it was reading the line "PlayerName==Steven" it would output "Pl", "lay", "ayer", "yerNa", "erNa", "rNa", and finally "Na" then ignore the rest of the line.

If anyone has experienced this before please help because this bug does not make sense to me at all.

8
never mind i found the problem.  the array of sprites i was using i set the array size to be one smaller of the amount of objects i was putting into the array. i was thinking for a 11x9 grid it would be
Code: [Select]
bgTile[10][8] since it starts at bgTile[0][0] but it was looking for the actual size of the array.

9
Hi guys, I'm new to SFML and only a novice at c++.  In order to practice I was trying to make my own 2d game.  I was trying to make it so the background is a tiled background and use a loop to render each one onto the screen since its 11x9 so i didnt have to individually set each sprite.  But this loop is giving me  the error First-chance exception at 0x003a6618 in GameTest.exe: 0xC0000005: Access violation reading location 0x60023e54.  The code itself compiles and runs and when the game gets to the point
Code: [Select]
for (int y = 0; y < cellsY; y++)
{
for (int x = 0; x < cellsX; x++)
{
broken(broke);
broke++;
bgTile[x][y] = *sPointer;
bgTile[x][y].setPosition((x*64.f), (y*64.f));
}
}
is when i get the error, after the two loops have been run. (the console reads that its breaking after the 99th break output which would mean it has to be breaking on
Code: [Select]
bgTile[x][y] = *sPointer;
bgTile[x][y].setPosition((x*64.f), (y*64.f));

heres the entire file so you can see what i did wrong since that one snippet probably isnt a major help

Code: [Select]
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

#define cellsX 11
#define cellsY 9
#define cellSize 64

int gameState = 0;

void broken(int breakNum)
{
std::cout << "Break : " << breakNum << "." << std::endl;
return;
}

int main()
{
// Create our window
sf::RenderWindow window(sf::VideoMode(cellsX*cellSize, cellsY*cellSize), "Game Test");

sf::Texture grassTile;
sf::Texture mainChar;

sf::Sprite bgTile[cellsX-1][cellsY-1];
sf::Sprite mnChar;
sf::Sprite gTile;
sf::Sprite * sPointer;
sPointer = &gTile;

if(!grassTile.loadFromFile("grass.png"))
{
return 0;
}
if (!mainChar.loadFromFile("mainchar.png"))
{
return 0;
}
mnChar.setTexture(mainChar);
mnChar.setPosition(5.f*cellSize, 4.f*cellSize);
gTile.setTexture(grassTile);
gTile.setPosition(0.f, 0.f);

int broke = 1;

for (int y = 0; y < cellsY; y++)
{
for (int x = 0; x < cellsX; x++)
{
broken(broke);
broke++;
bgTile[x][y] = *sPointer;
bgTile[x][y].setPosition((x*64.f), (y*64.f));
}
}

sf::Clock updateClock;
sf::Time updateTime = sf::milliseconds(333);

//Starts the game loop
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
broken(broke);
broke++;
if (updateClock.getElapsedTime().asMilliseconds() >= updateTime.asMilliseconds())
{
switch (gameState)
{
case 0:
{
broken(broke);
broke++;
for (int y = 0; y < cellsY; y++)
{
for (int x = 0; x < cellsX; x++)
{
window.draw(bgTile[x][y]);
broken(broke);
broke++;
}
}

window.draw(mnChar);
broken(broke);
broke++;
}
}
window.display();
}
}
}

return 0;
}

Please, i only need help fixing the one access violation.  Please dont try to correct the sloppyness of my coding, this is all me screwing around with c++ after moving from c# and learning sfml. the codes going to get cleaner once i get all this simple crap down

Pages: [1]
anything