Files @ r23882:d683a0787bc9
Branch filter:

Location: cpp/openttd-patchpack/source/src/story_base.h - annotation

Nikolas Nyby
Codechange: Don't use SDL_CreateRGBSurfaceWithFormat()

This function requires libSDL 2.0.5 or higher. It looks like we don't
need to use it, and can just use the original SDL_CreateRGBSurface(),
with the masks set to 0, to trigger the default 8-bit format, which is
SDL_PIXELFORMAT_INDEX8.

Closes #7785

Note: this code path is activated by using an 8-bit blitter, like:

./bin/openttd -b 8bpp-simple
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r23665:a125a7eabac3
r20584:e112b5dd0ddd
r20329:0b11d054e50d
r20329:0b11d054e50d
r20584:e112b5dd0ddd
r20584:e112b5dd0ddd
r20329:0b11d054e50d
r20329:0b11d054e50d
r20584:e112b5dd0ddd
r20584:e112b5dd0ddd
r20584:e112b5dd0ddd
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20584:e112b5dd0ddd
r23665:a125a7eabac3
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r23607:36c15679007d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20585:41a511c50437
r20585:41a511c50437
r20585:41a511c50437
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r23674:a5bafa1a02c5
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r23607:36c15679007d
r20329:0b11d054e50d
r20585:41a511c50437
r20585:41a511c50437
r20585:41a511c50437
r20585:41a511c50437
r20585:41a511c50437
r20585:41a511c50437
r20585:41a511c50437
r20585:41a511c50437
r20585:41a511c50437
r20585:41a511c50437
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
r20329:0b11d054e50d
/* $Id$ */

/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file story_base.h %StoryPage base class. */

#ifndef STORY_BASE_H
#define STORY_BASE_H

#include "company_type.h"
#include "story_type.h"
#include "date_type.h"
#include "core/pool_type.hpp"

typedef Pool<StoryPageElement, StoryPageElementID, 64, 64000> StoryPageElementPool;
typedef Pool<StoryPage, StoryPageID, 64, 64000> StoryPagePool;
extern StoryPageElementPool _story_page_element_pool;
extern StoryPagePool _story_page_pool;
extern uint32 _story_page_element_next_sort_value;
extern uint32 _story_page_next_sort_value;

/*
 * Each story page element is one of these types.
 */
enum StoryPageElementType : byte {
	SPET_TEXT = 0, ///< A text element.
	SPET_LOCATION, ///< An element that references a tile along with a one-line text.
	SPET_GOAL,     ///< An element that references a goal.
	SPET_END,
	INVALID_SPET = 0xFF,
};

/** Define basic enum properties */
template <> struct EnumPropsT<StoryPageElementType> : MakeEnumPropsT<StoryPageElementType, byte, SPET_TEXT, SPET_END, INVALID_SPET, 8> {};

/**
 * Struct about story page elements.
 * Each StoryPage is composed of one or more page elements that provide
 * page content. Each element only contain one type of content.
 **/
struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> {
	uint32 sort_value;   ///< A number that increases for every created story page element. Used for sorting. The id of a story page element is the pool index.
	StoryPageID page; ///< Id of the page which the page element belongs to
	StoryPageElementType type; ///< Type of page element

	uint32 referenced_id; ///< Id of referenced object (location, goal etc.)
	char *text;           ///< Static content text of page element

	/**
	 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
	 */
	inline StoryPageElement() { }

	/**
	 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
	 */
	inline ~StoryPageElement() { free(this->text); }
};

#define FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPageElement, story_page_element_index, var, start)
#define FOR_ALL_STORY_PAGE_ELEMENTS(var) FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, 0)

/** Struct about stories, current and completed */
struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
	uint32 sort_value;   ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index.
	Date date;           ///< Date when the page was created.
	CompanyID company;   ///< StoryPage is for a specific company; INVALID_COMPANY if it is global

	char *title;         ///< Title of story page

	/**
	 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
	 */
	inline StoryPage() { }

	/**
	 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
	 */
	inline ~StoryPage()
	{
		if (!this->CleaningPool()) {
			StoryPageElement *spe;
			FOR_ALL_STORY_PAGE_ELEMENTS(spe) {
				if (spe->page == this->index) delete spe;
			}
		}
		free(this->title);
	}
};

#define FOR_ALL_STORY_PAGES_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPage, story_page_index, var, start)
#define FOR_ALL_STORY_PAGES(var) FOR_ALL_STORY_PAGES_FROM(var, 0)

#endif /* STORY_BASE_H */