<?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[Wohin mit der Initialisierungssequenz? Designfrage]]></title><description><![CDATA[<p>Hallo</p>
<p>Für eine GUI wollt ich gern SDL und Guichan verwenden. Hab nun eine Factory für Views und das ganze mal mit den Standardein- und ausgaben umgesetzt. Soweit so gut.</p>
<p>Für eine SDL Anwendung muss ich ja einiges initialisieren und Ressourcen (Zeiger, Screenobjekte, Bitmaps und Fonts, etc..) anfordern und wieder ordentlich freigeben.</p>
<p>1. Mach ich nun die Initialisierung in den Ctor und das Aufräumen in den Dtor der Factory oder lass ich den eine andere Klasse aufrufen, die sich darum kümmert?<br />
2. Sollte ich für jedes Bitmap etc. eine eigene, Ressourcen verwaltende Klasse machen oder würdet ihr das alle in eine gemeinsame (ev. die gleiche wie in 1.?) packen?</p>
<p>Bitte habt Nachsicht, ich versuch mir selbst gutes Design beizubringen, und wär sehr froh um Tipps von Provis <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Danke im voraus<br />
Grüsse<br />
Sebi</p>
<p>PS: Hier noch die Init. und Aufräum Funktionen aus dem Tutorial. Diesen Code möcht ich schön verpacken, globale Variablen und Zeiger mit new/delete loswerden:</p>
<pre><code class="language-cpp">/*
 * SDL Stuff we need
 */
SDL_Surface* screen;
SDL_Event event;

/*
 * Guichan SDL stuff we need
 */
gcn::SDLInput* input;             // Input driver
gcn::SDLGraphics* graphics;       // Graphics driver
gcn::SDLImageLoader* imageLoader; // For loading images

/*
 * Guichan stuff we need
 */
gcn::Gui* gui;            // A Gui object - binds it all together
gcn::Container* top;      // A top container
gcn::ImageFont* font;     // A font
gcn::Label* label;        // And a label for the Hello World text

/**
 * Initializes the Hello World
 */
void init()
{
	/*
	 * Here we initialize SDL as we would do with any SDL application.
	 */
	SDL_Init(SDL_INIT_VIDEO);
	screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
	// We want unicode
	SDL_EnableUNICODE(1);
	// We want to enable key repeat
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

	/*
	 * Now it's time for Guichan SDL stuff
	 */
	imageLoader = new gcn::SDLImageLoader();
	// The ImageLoader in use is static and must be set to be
	// able to load images
	gcn::Image::setImageLoader(imageLoader);
	graphics = new gcn::SDLGraphics();
	// Set the target for the graphics object to be the screen.
	// In other words, we will draw to the screen.
	// Note, any surface will do, it doesn't have to be the screen.
	graphics-&gt;setTarget(screen);
	input = new gcn::SDLInput();

	/*
	 * Last but not least it's time to initialize and create the gui
	 * with Guichan stuff.
	 */
	top = new gcn::Container();
	// Set the dimension of the top container to match the screen.
	top-&gt;setDimension(gcn::Rectangle(0, 0, 640, 480));
	gui = new gcn::Gui();
	// Set gui to use the SDLGraphics object.
	gui-&gt;setGraphics(graphics);
	// Set gui to use the SDLInput object
	gui-&gt;setInput(input);
	// Set the top container
	gui-&gt;setTop(top);
	// Load the image font.
	font = new gcn::ImageFont(&quot;fixedfont.bmp&quot;, &quot; abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&quot;);
	// The global font is static and must be set.
	gcn::Widget::setGlobalFont(font);

	// Create a label with test hello world
	label = new gcn::Label(&quot;Hello World&quot;);
	// Set the labels position
	label-&gt;setPosition(280, 220);
	// Add the label to the top container
	top-&gt;add(label);
}

/**
 * Halts the application
 */
void halt()
{
	/*
	 * Destroy Guichan stuff
	 */
	delete label;
	delete font;
	delete top;
	delete gui;

	/*
	 * Destroy Guichan SDL stuff
	 */
	delete input;
	delete graphics;
	delete imageLoader;

	/*
	 * Destroy SDL stuff
	 */
	SDL_Quit();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/171817/wohin-mit-der-initialisierungssequenz-designfrage</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Jul 2026 18:36:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/171817.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Jan 2007 17:30:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wohin mit der Initialisierungssequenz? Designfrage on Mon, 29 Jan 2007 17:30:13 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Für eine GUI wollt ich gern SDL und Guichan verwenden. Hab nun eine Factory für Views und das ganze mal mit den Standardein- und ausgaben umgesetzt. Soweit so gut.</p>
<p>Für eine SDL Anwendung muss ich ja einiges initialisieren und Ressourcen (Zeiger, Screenobjekte, Bitmaps und Fonts, etc..) anfordern und wieder ordentlich freigeben.</p>
<p>1. Mach ich nun die Initialisierung in den Ctor und das Aufräumen in den Dtor der Factory oder lass ich den eine andere Klasse aufrufen, die sich darum kümmert?<br />
2. Sollte ich für jedes Bitmap etc. eine eigene, Ressourcen verwaltende Klasse machen oder würdet ihr das alle in eine gemeinsame (ev. die gleiche wie in 1.?) packen?</p>
<p>Bitte habt Nachsicht, ich versuch mir selbst gutes Design beizubringen, und wär sehr froh um Tipps von Provis <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Danke im voraus<br />
Grüsse<br />
Sebi</p>
<p>PS: Hier noch die Init. und Aufräum Funktionen aus dem Tutorial. Diesen Code möcht ich schön verpacken, globale Variablen und Zeiger mit new/delete loswerden:</p>
<pre><code class="language-cpp">/*
 * SDL Stuff we need
 */
SDL_Surface* screen;
SDL_Event event;

/*
 * Guichan SDL stuff we need
 */
gcn::SDLInput* input;             // Input driver
gcn::SDLGraphics* graphics;       // Graphics driver
gcn::SDLImageLoader* imageLoader; // For loading images

/*
 * Guichan stuff we need
 */
gcn::Gui* gui;            // A Gui object - binds it all together
gcn::Container* top;      // A top container
gcn::ImageFont* font;     // A font
gcn::Label* label;        // And a label for the Hello World text

/**
 * Initializes the Hello World
 */
void init()
{
	/*
	 * Here we initialize SDL as we would do with any SDL application.
	 */
	SDL_Init(SDL_INIT_VIDEO);
	screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
	// We want unicode
	SDL_EnableUNICODE(1);
	// We want to enable key repeat
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

	/*
	 * Now it's time for Guichan SDL stuff
	 */
	imageLoader = new gcn::SDLImageLoader();
	// The ImageLoader in use is static and must be set to be
	// able to load images
	gcn::Image::setImageLoader(imageLoader);
	graphics = new gcn::SDLGraphics();
	// Set the target for the graphics object to be the screen.
	// In other words, we will draw to the screen.
	// Note, any surface will do, it doesn't have to be the screen.
	graphics-&gt;setTarget(screen);
	input = new gcn::SDLInput();

	/*
	 * Last but not least it's time to initialize and create the gui
	 * with Guichan stuff.
	 */
	top = new gcn::Container();
	// Set the dimension of the top container to match the screen.
	top-&gt;setDimension(gcn::Rectangle(0, 0, 640, 480));
	gui = new gcn::Gui();
	// Set gui to use the SDLGraphics object.
	gui-&gt;setGraphics(graphics);
	// Set gui to use the SDLInput object
	gui-&gt;setInput(input);
	// Set the top container
	gui-&gt;setTop(top);
	// Load the image font.
	font = new gcn::ImageFont(&quot;fixedfont.bmp&quot;, &quot; abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&quot;);
	// The global font is static and must be set.
	gcn::Widget::setGlobalFont(font);

	// Create a label with test hello world
	label = new gcn::Label(&quot;Hello World&quot;);
	// Set the labels position
	label-&gt;setPosition(280, 220);
	// Add the label to the top container
	top-&gt;add(label);
}

/**
 * Halts the application
 */
void halt()
{
	/*
	 * Destroy Guichan stuff
	 */
	delete label;
	delete font;
	delete top;
	delete gui;

	/*
	 * Destroy Guichan SDL stuff
	 */
	delete input;
	delete graphics;
	delete imageLoader;

	/*
	 * Destroy SDL stuff
	 */
	SDL_Quit();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1219306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1219306</guid><dc:creator><![CDATA[THX 1138]]></dc:creator><pubDate>Mon, 29 Jan 2007 17:30:13 GMT</pubDate></item><item><title><![CDATA[Reply to Wohin mit der Initialisierungssequenz? Designfrage on Mon, 29 Jan 2007 20:11:05 GMT]]></title><description><![CDATA[<p>was man explizit machen muss (Aufruf von halt zB) vergisst man schnell zB weil man nicht alle möglichen Programm-Pfade berücksichtigt (Exceptions).</p>
<p>Dtoren funktionieren aber implizit. Daher sind die zum aufräumen vorzuziehen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1219405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1219405</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Mon, 29 Jan 2007 20:11:05 GMT</pubDate></item><item><title><![CDATA[Reply to Wohin mit der Initialisierungssequenz? Designfrage on Tue, 30 Jan 2007 02:38:40 GMT]]></title><description><![CDATA[<ol>
<li></li>
</ol>
<p>seperate funktionen zum releasen sind OK, sogar gut (laut irgend so nem C++ buch das ich vor jahren las, koennte <a href="http://www.amazon.com/Effective-C%2B%2B-Addison-Wesley-Professional-Computing/dp/0321334876/" rel="nofollow">http://www.amazon.com/Effective-C%2B%2B-Addison-Wesley-Professional-Computing/dp/0321334876/</a> sein).</p>
<p>Wichtig ist dabei, das die Init function prueft ob schonmal initialisiert wurde und dann entweder einen errorcode zurueckliefert, oder erstmal das release aufruft.</p>
<p>release sollte dann auch immer pruefen ob ueberhaupt was zum freigeben ist. das kann man auch pro variable machen, dazu wird oft SAFE_RELEASE benutzt (google mal danach, du findest es tausend mal und immer gleich implementiert (c&amp;p ;))</p>
<p>so ein paar anmerkungen:<br />
- es bieten sich singletons fuer factories an.<br />
- es ist zwar schoen einzelne labels usw. zu erstellen, aber genau so wie man keine polygonmeshes im code erzeugt, sollte man das bei GUI nicht machen und versuchen auch sie zu laden, gerade dafuer bietet sich XML sehr an. es gibt auch schon bekannte formate wie z.b. von das von Gnom.</p>
<ol start="2">
<li></li>
</ol>
<p>Eine resource hat ja klar definiete funktionen, egal ob font oder bitmap oder...<br />
Also machst du dir eine Resource klasse die sich um alles noetige kuemmert.<br />
Falls du eine spezielle Bitmap brauchst, weil sie z.b. erst bei der ersten verwendung die bitmap wirklich laedt, leitest du von der resource ab und spezialisiert die noetigen funktionen oder packst neue hinzu.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1219517</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1219517</guid><dc:creator><![CDATA[rapso]]></dc:creator><pubDate>Tue, 30 Jan 2007 02:38:40 GMT</pubDate></item><item><title><![CDATA[Reply to Wohin mit der Initialisierungssequenz? Designfrage on Tue, 30 Jan 2007 14:54:27 GMT]]></title><description><![CDATA[<p>Singleton ist klar, und das mit den Labels etc. auch.<br />
S geht mir echt nur um die Ressourcen, soweit auch klar.<br />
Danke erstmal.</p>
<p>Was mir noch unklar ist, ob die Factory selbst die API initialisieren soll, oder eine weitere Klasse braucht, die dann die API Funktionen kapselt..quasi delegiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1219869</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1219869</guid><dc:creator><![CDATA[THX 1138]]></dc:creator><pubDate>Tue, 30 Jan 2007 14:54:27 GMT</pubDate></item></channel></rss>