Jump to content
  • Advertisement

SlashC++Programmer

Member
  • Content Count

    17
  • Joined

  • Last visited

Community Reputation

139 Neutral

About SlashC++Programmer

  • Rank
    Member
  1. SlashC++Programmer

    Does Object Pooling with a Vector in C++ have problems with memory?

    WOW! guys thank you very much for  the feedback.  :D From what I'm hearing in C++ I really only need 2 vectors like _Martain said. One for active bullets and the other for inactive bullets. Then I just swap the inactive bullets with active bullets when I want my BulletPool to get one. They have to be pointers though so I'm not making a copy. Instead I'm doing a reference for this to work right?.
  2. SlashC++Programmer

    Does Object Pooling with a Vector in C++ have problems with memory?

      Thank you very much again Oberon_Command. :D Hopefully I have it right like you said.   main.cpp http://pastebin.com/JHGkJAFA   BulletPool Class http://paste.ubuntu.com/18758862/
  3. SlashC++Programmer

    Does Object Pooling with a Vector in C++ have problems with memory?

      I'm trying to follow this video on object pooling with flash.    http://gotoandlearn.com/play.php?id=160   I'm trying to convert it to C++. This is what I'm trying to do.   Define a pool class that maintains a collection of reusable objects. Each object supports an “in use” query to tell if it is currently “alive”. When the pool is initialized, it creates the entire collection of objects up front (usually in a single contiguous allocation) and initializes them all to the “not in use” state. When you want a new object, ask the pool for one. It finds an available object, initializes it to “in use”, and returns it. When the object is no longer needed, it is set back to the “not in use” state. This way, objects can be freely created and destroyed without needing to allocate memory or other resources.
  4. SlashC++Programmer

    Does Object Pooling with a Vector in C++ have problems with memory?

    This code keeps track of it so it should be fine I think.    void ReturnBullet(Bullet *bullet) // return the bullet back to the pool by reference  {         mBullets[mCounter++] = bullet;  }  
  5. SlashC++Programmer

    Does Object Pooling with a Vector in C++ have problems with memory?

      Thank you very much again guys :D Hopefully I have it now use by reference and not by value.   Here is my new code updated again. main.cpp http://pastebin.com/7uqmHXQ3   BulletPool Class http://pastebin.com/zqfSj19U
  6. SlashC++Programmer

    Does Object Pooling with a Vector in C++ have problems with memory?

    Thanks you very much guys for the help :D I reworked my code from what you guys told me. How is it now?   Here is my new code updated main.cpp http://pastebin.com/iz028sdY   BulletPool class http://pastebin.com/3qPzq9Ra
  7. SlashC++Programmer

    Does Object Pooling with a Vector in C++ have problems with memory?

      Here is my BulletPool class. Thank you very much for helping me out. :D   http://pastebin.com/ri79ydYm
  8. Hi guys,   I made some Object Pooling with a Vector in C++. The problem is though does the push_back() and erase() cause memory problems?   Here is my code below http://pastebin.com/KQL6NRn2
  9. SlashC++Programmer

    How do I re-size a binary file?

    Hi guys thanks. So I can't just load the whole thing in memory? Loading the whole thing in memory causes prolems? Yes I'm making a file.ty that has a lot of batman assets in it. The reason I hardcoded it at the top was to give you an idea what I'm facing.
  10. SlashC++Programmer

    How do I re-size a binary file?

    Hii I'm trying to re-size a binary file. It's seems when I do this it's off by 8 bytes. If I use a different file it might be 3 or 5 bytes.   Here is my re-size code: // index the beginning of the new .bik file int index = 2160640; // files to load std::ifstream readFile("baa_logo_run_v5_h264.bik", std::ifstream::binary); std::ifstream readFile2("riddeler.bik", std::ifstream::binary); // length of old file long length = 9972608; // get size of readFile readFile.seekg(0, readFile.end); long size = readFile.tellg(); readFile.seekg(0); // get size of readFile2 readFile2.seekg(0, readFile2.end); long size2 = readFile2.tellg(); readFile2.seekg(0); // allocate memory for file content char* readBuffer1 = new char[size]; char* readBuffer2 = new char[size2]; // read contents in buffer readFile.read(readBuffer1, size); readFile2.read(readBuffer2, size2); readFile.close(); readFile2.close(); // file to write to std::ofstream WriteFile("myfile.ty", std::ofstream::binary); // update new bik files // .bik file size is less than current bik length if (size2 < length) { // re-size writeBuffer long newSize = size - (length - size2); char* writeBuffer = new char[newSize]; // rebuild file again for (int i = 0; i < newSize; i++) { writeBuffer[i] = readBuffer1[i]; } // counters and flag int num = 0; int num2 = 0; int flag = 0; // length of the whole file for (int i = index; i < newSize; i++) { // length of the new bik file if (num < size2) { writeBuffer[i] = readBuffer2[num]; } num++; // if the new bik is stored then flag = 1 if (num > size2) { flag = 1; } // write the rest of the other files. if (flag == 1) { if (num2 < newSize && index + length + num2 < newSize) { writeBuffer[i] = readBuffer1[(index + length + num2)]; } num2++; } } // write to file WriteFile.write(writeBuffer, newSize); WriteFile.close(); delete[] writeBuffer; } // end of rebuild file
  11. SlashC++Programmer

    Hi anyone want c++ game partner?

    Hi I'm looking for a partner to code a new game or project with. I have worked with win api, sfml lib and some opengl using c++ If anyone is interested page me.
  12. oops the code was wrong a little bit here is the new code update.    // search neighbours         lowestGCost = openList[i-7].GCost;         for (int i = openListNum-6; i < openListNum; i++)         {                 if (openList(i).GCost < lowestGCost)             {                     lowestGCost = openList.GCost;                 if (lowestGCost < closeList[closeListNum].GCost)                 {                                 closeList[closeListNum].Num = openList.Num;                     closeList[closeListNum].GridX = openList.GridX;                     closeList[closeListNum].GridY = openList.GridY;                     closeList[closeListNum].Heuristic = openList.Heuristic;                     closeList[closeListNum].Parent = openList.Parent;                     closeList[closeListNum].GCost = openList.GCost;                     closeList[closeListNum].FCost = openList.FCost;                                        }                             }                    }
  13. I need help with A* pathfinding searching the neighbours for lowest GCost Guys I got the a* pathfinder almost down but my search neighbors for the lowest GCost code isn't working. That code below should compare the last closeList index closeListNum with the the openList -7 index. It searches 8 moves back for the lowest GCost. I hope someone can help me out with this. :)    // search neighbours         lowestGCost = closeList[i-7].GCost;         for (int i = openListNum-6; i < openListNum; i++)         {                 if (openList(i).GCost < lowestGCost)             {                     lowestGCost = openList.GCost;                 if (lowestGCost < closeList[closeListNum].GCost)                 {                                 closeList[closeListNum].Num = openList.Num;                     closeList[closeListNum].GridX = openList.GridX;                     closeList[closeListNum].GridY = openList.GridY;                     closeList[closeListNum].Heuristic = openList.Heuristic;                     closeList[closeListNum].Parent = openList.Parent;                     closeList[closeListNum].GCost = openList.GCost;                     closeList[closeListNum].FCost = openList.FCost;                                        }                             }                    }
  14. SlashC++Programmer

    Hi guys is there anyone that could help me with pathfinding in C++?

    I watched a video on (What is A* Pathfinding) youtube I know the logic behind it. The code I write isn't matching up though. :(
  15. SlashC++Programmer

    Hi guys is there anyone that could help me with pathfinding in C++?

    Thank you minibutmany Yeah it was a mistake to post twice. I tried to delete one but I couldn't find the delete post button.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!