<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Iterationsproblem]]></title><description><![CDATA[<p>Hallo, Ich habe folgendes Problem:</p>
<p>Ich habe eine Datei die eine Tilemap repräsentiert die in eine Datenstruktur überführt werden soll.<br />
Und zwar ist es Ziel zum Schluss einen Vector von Tiles zubekommen die dann anderweitig verarbeitet<br />
werden können.<br />
Die Map hat folgendes format:</p>
<pre><code>1,0 1,0 1,0 1,0 1,1 1,0 1,0 1,0 1,0 1,0
1,0 x,x x,x x,x x,x x,x x,x x,x x,x 1,0
1,0 x,x x,x x,x 0,0 x,x x,x x,x x,x 1,0
1,0 1,0 x,x x,x 1,0 x,x 1,1 x,x x,x 1,0
1,0 x,x x,x x,x 2,0 x,x x,x x,x x,x 1,0
1,0 x,x x,x x,x 3,0 1,1 0,0 x,x x,x 1,0
1,0 x,x x,x x,x x,x x,x x,x x,x x,x 1,0
1,0 x,x x,x x,x x,x x,x x,x x,x x,x 1,0
1,0 x,x x,x x,x x,x x,x x,x x,x x,x 1,0
1,0 1,0 1,0 1,0 1,0 1,0 1,0 1,0 1,0 1,0
</code></pre>
<p>Um dies zu erreichen habe ich zwei Funktionen:</p>
<pre><code>void Layer::CheckMap(std::string value,sf::Vector2i&amp; globalposition)
        {
            std::string xx = value.substr(0,value.find(',')); //Find X component of coordinate in the tileset
            std::string yy = value.substr(value.find(',')+1); //Find y component of coordinate in the tileset

            int x,y,i,j;

            for(i = 0; i&lt; xx.length();i++)
            {
                if(!std::isdigit(xx[i]))
                    break;
            }

            for(j = 0; j&lt; yy.length();j++)
            {
                if(!std::isdigit(yy[j]))
                    break;
            }

            x = (i == xx.length()) ? std::atoi(xx.c_str()) : -1;
            y = (j == yy.length()) ? std::atoi(yy.c_str()) : -1;

            //Trauriger versuch...
            globalposition.x++;
            Tile* tmp = new Tile(this-&gt;m_Tileset,sf::Vector2i(x,y),globalposition,sf::Vector2i(32,32),0);
            this-&gt;m_Tiles.push_back(tmp);
        }

        void Layer::LoadLayer()
        {
            std::stringstream           cstream(this-&gt;m_LayerSource); //Charakterstream
            std::string                 value;
            sf::Vector2i                globalposition(0,0);
            if(this-&gt;m_Tileset == NULL)
            {
                this-&gt;m_Tileset = new graphic::Tileset(this-&gt;m_Tilesetpath,32);
            }

            while(!cstream.eof())
            {

                while(std::getline(cstream,value,' '))
                {
                    if(value.length() &gt; 0)
                    {
                        this-&gt;CheckMap(value,globalposition);

                         std::cerr&lt;&lt;&quot;x|y -- &quot;&lt;&lt;globalposition.x&lt;&lt;&quot;|&quot;&lt;&lt;globalposition.y&lt;&lt;&quot;\n&quot;;
                    }
                    globalposition.y++;

                }
                globalposition.x = 0;

            }
        }
</code></pre>
<p>Das Problem ist, das die Funktion CheckMap nicht erkennen kann wann innerhalb einer Zeile diese Zu Ende ist. Wodurch X immer weiter inkrementiert wird und so nie auf null gesetzt werden kann. getline holt hier auch nicht eine Zeile sondern nur ein object der Form (x,y) bis zum nächsten seperator &quot; &quot;.<br />
Ich benötige aber die Information wo auf der Karte ein Tile ist um später diese unterandem Korrekt auf dem Bildschirm zu zeichnen</p>
<p>Ich habe das gefühl das ich ein Brett vor dem Kopf habe, weil mir auch keine andere Lösung für das problem Momentan einfällt.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/320938/iterationsproblem</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 13:14:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/320938.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Oct 2013 20:33:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Iterationsproblem on Thu, 17 Oct 2013 20:33:20 GMT]]></title><description><![CDATA[<p>Hallo, Ich habe folgendes Problem:</p>
<p>Ich habe eine Datei die eine Tilemap repräsentiert die in eine Datenstruktur überführt werden soll.<br />
Und zwar ist es Ziel zum Schluss einen Vector von Tiles zubekommen die dann anderweitig verarbeitet<br />
werden können.<br />
Die Map hat folgendes format:</p>
<pre><code>1,0 1,0 1,0 1,0 1,1 1,0 1,0 1,0 1,0 1,0
1,0 x,x x,x x,x x,x x,x x,x x,x x,x 1,0
1,0 x,x x,x x,x 0,0 x,x x,x x,x x,x 1,0
1,0 1,0 x,x x,x 1,0 x,x 1,1 x,x x,x 1,0
1,0 x,x x,x x,x 2,0 x,x x,x x,x x,x 1,0
1,0 x,x x,x x,x 3,0 1,1 0,0 x,x x,x 1,0
1,0 x,x x,x x,x x,x x,x x,x x,x x,x 1,0
1,0 x,x x,x x,x x,x x,x x,x x,x x,x 1,0
1,0 x,x x,x x,x x,x x,x x,x x,x x,x 1,0
1,0 1,0 1,0 1,0 1,0 1,0 1,0 1,0 1,0 1,0
</code></pre>
<p>Um dies zu erreichen habe ich zwei Funktionen:</p>
<pre><code>void Layer::CheckMap(std::string value,sf::Vector2i&amp; globalposition)
        {
            std::string xx = value.substr(0,value.find(',')); //Find X component of coordinate in the tileset
            std::string yy = value.substr(value.find(',')+1); //Find y component of coordinate in the tileset

            int x,y,i,j;

            for(i = 0; i&lt; xx.length();i++)
            {
                if(!std::isdigit(xx[i]))
                    break;
            }

            for(j = 0; j&lt; yy.length();j++)
            {
                if(!std::isdigit(yy[j]))
                    break;
            }

            x = (i == xx.length()) ? std::atoi(xx.c_str()) : -1;
            y = (j == yy.length()) ? std::atoi(yy.c_str()) : -1;

            //Trauriger versuch...
            globalposition.x++;
            Tile* tmp = new Tile(this-&gt;m_Tileset,sf::Vector2i(x,y),globalposition,sf::Vector2i(32,32),0);
            this-&gt;m_Tiles.push_back(tmp);
        }

        void Layer::LoadLayer()
        {
            std::stringstream           cstream(this-&gt;m_LayerSource); //Charakterstream
            std::string                 value;
            sf::Vector2i                globalposition(0,0);
            if(this-&gt;m_Tileset == NULL)
            {
                this-&gt;m_Tileset = new graphic::Tileset(this-&gt;m_Tilesetpath,32);
            }

            while(!cstream.eof())
            {

                while(std::getline(cstream,value,' '))
                {
                    if(value.length() &gt; 0)
                    {
                        this-&gt;CheckMap(value,globalposition);

                         std::cerr&lt;&lt;&quot;x|y -- &quot;&lt;&lt;globalposition.x&lt;&lt;&quot;|&quot;&lt;&lt;globalposition.y&lt;&lt;&quot;\n&quot;;
                    }
                    globalposition.y++;

                }
                globalposition.x = 0;

            }
        }
</code></pre>
<p>Das Problem ist, das die Funktion CheckMap nicht erkennen kann wann innerhalb einer Zeile diese Zu Ende ist. Wodurch X immer weiter inkrementiert wird und so nie auf null gesetzt werden kann. getline holt hier auch nicht eine Zeile sondern nur ein object der Form (x,y) bis zum nächsten seperator &quot; &quot;.<br />
Ich benötige aber die Information wo auf der Karte ein Tile ist um später diese unterandem Korrekt auf dem Bildschirm zu zeichnen</p>
<p>Ich habe das gefühl das ich ein Brett vor dem Kopf habe, weil mir auch keine andere Lösung für das problem Momentan einfällt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360994</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360994</guid><dc:creator><![CDATA[exofde]]></dc:creator><pubDate>Thu, 17 Oct 2013 20:33:20 GMT</pubDate></item><item><title><![CDATA[Reply to Iterationsproblem on Fri, 18 Oct 2013 05:19:13 GMT]]></title><description><![CDATA[<p>Du könntest erstmal durch die Zeilen iterieren und diese anschließend in die Werte aufspalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2361046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2361046</guid><dc:creator><![CDATA[Youka]]></dc:creator><pubDate>Fri, 18 Oct 2013 05:19:13 GMT</pubDate></item><item><title><![CDATA[Reply to Iterationsproblem on Fri, 18 Oct 2013 05:24:56 GMT]]></title><description><![CDATA[<p>Oh grauen.</p>
<p>1. benutze getline bis zum Zeilenende(wahrscheinlich ist das gar nicht nötig, aber ich will dir jetzt nicht zu nem ordentlichen parser raten)<br />
2. benutze std::stringstream zum lesen der ints aus der Zeile und bastel nicht mit atoi oder ähnlichem rum. Mach nur vorher ein peek um zu sehen, ob das erste Zeichen ein x ist.<br />
3. vorwärtsdeklaration von variablen innerhalb einer Funktion ist höchst unübersichtlich<br />
4. Wenn du einen Vektor von Tiles haben willst, dann solltest du einen Vektor von Tiles erzeugen, und nicht einen Vektor von pointern auf Tiles. Das erspart dir eine Menge Scherereien (Thema Exceptions und Geschwindigkeit und Codekomplexität...)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2361047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2361047</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Fri, 18 Oct 2013 05:24:56 GMT</pubDate></item></channel></rss>