Tuesday, October 11, 2022
HomeGame Developmentc++ - Loading form knowledge from a textual content file

c++ – Loading form knowledge from a textual content file


I am self-learning into recreation improvement and I got here throughout an issue, that I want some enter.

I am utilizing C++ and SFML 2.5.1

I wish to load knowledge from a file, that knowledge will inform me what to attract when it comes to object placement into the world.

So as an example I am utilizing a standard Textual content File and I wish to processthe following information:

  • Kind (The wireframe of the thing);
  • ID
  • Identify
  • Place
  • Moveable

So, I can learn and course of that information right into a vector of strings. All is nice to date. My query is now what to do with this:

My first strategy was to create a GameObject Class that takes a string at creation and processes that string into an inner struct.

std::stringstream ss(knowledge);
std::vector<std::string> processedData;
std::string delim = " ";
std::string s;

whereas(std::getline(ss, s, ' '))
{
    processedData.push_back(s);
}

if(processedData[0] == "Circle")
{
    m_Data.sort = processedData[0];
    m_Data.title = processedData[1];
    m_Data.initialPosition.x = stoi(processedData[2]);
    m_Data.initialPosition.y = stoi(processedData[3]);

Now I can create a GameShape object and I can entry the info within the struct within the object.

 GameShape form("Circle 00001 Vase 100 100 1");
sf::CircleShape circle;
    circle.setPosition(form.m_Data.initialPosition.x, form.m_Data.initialPosition.y);
    circle.setFillColor(sf::Coloration(form.m_Data.coloration.r, form.m_Data.coloration.g, form.m_Data.coloration.b));
    circle.setRadius(form.m_Data.radius);

Now right here lies my downside. I consider I over difficult this, and there must be a greater means to do that, I feel I doing this the flawed means.

Ought to I drop the struct and use the GameShape class to course of a spit out the specified form by inherinting from SFML form and utilizing it to govern the thing?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments