Files
@ r28098:2f7e0d913c81
Branch filter:
Location: cpp/openttd-patchpack/source/src/game/game_info.cpp - annotation
r28098:2f7e0d913c81
4.9 KiB
text/x-c
Add: Mock sprite cache intialization.
This fills up the sprite cache with SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT zero-size sprites, to
allow GetSpriteSize() calls to continue from unit-tests.
This fills up the sprite cache with SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT zero-size sprites, to
allow GetSpriteSize() calls to continue from unit-tests.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r21383:942c32fb8b0e r21383:942c32fb8b0e r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r27352:2279f2687a7b r18748:5e4b96072e2a r26708:fcfe8e5e499a r24108:7efb3e692372 r18748:5e4b96072e2a r18748:5e4b96072e2a r23088:6710c4c79ac6 r18748:5e4b96072e2a r23088:6710c4c79ac6 r27106:2d95beb51290 r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r27106:2d95beb51290 r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r23607:36c15679007d r25705:db1afb7a7392 r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r27369:d93808e810cd r27369:d93808e810cd r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18755:ade8fc0cd811 r27369:d93808e810cd r27369:d93808e810cd r18755:ade8fc0cd811 r18755:ade8fc0cd811 r18755:ade8fc0cd811 r18748:5e4b96072e2a r18748:5e4b96072e2a r27369:d93808e810cd r18748:5e4b96072e2a r25655:1030dcb7eb52 r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r23607:36c15679007d r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r27352:2279f2687a7b r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r27369:d93808e810cd r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 | /*
* 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 game_info.cpp Implementation of GameInfo */
#include "../stdafx.h"
#include "../script/squirrel_class.hpp"
#include "game_info.hpp"
#include "game_scanner.hpp"
#include "../debug.h"
#include "../safeguards.h"
/**
* Check if the API version provided by the Game is supported.
* @param api_version The API version as provided by the Game.
*/
static bool CheckAPIVersion(const std::string &api_version)
{
static const std::set<std::string> versions = { "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "12", "13", "14" };
return versions.find(api_version) != versions.end();
}
#if defined(_WIN32)
#undef GetClassName
#endif /* _WIN32 */
template <> const char *GetClassName<GameInfo, ScriptType::GS>() { return "GSInfo"; }
/* static */ void GameInfo::RegisterAPI(Squirrel *engine)
{
/* Create the GSInfo class, and add the RegisterGS function */
DefSQClass<GameInfo, ScriptType::GS> SQGSInfo("GSInfo");
SQGSInfo.PreRegister(engine);
SQGSInfo.AddConstructor<void (GameInfo::*)(), 1>(engine, "x");
SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddSetting, "AddSetting");
SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddLabels, "AddLabels");
SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_NONE, "CONFIG_NONE");
SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_RANDOM, "CONFIG_RANDOM");
SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_BOOLEAN, "CONFIG_BOOLEAN");
SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_INGAME, "CONFIG_INGAME");
SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_DEVELOPER, "CONFIG_DEVELOPER");
SQGSInfo.PostRegister(engine);
engine->AddMethod("RegisterGS", &GameInfo::Constructor, 2, "tx");
}
/* static */ SQInteger GameInfo::Constructor(HSQUIRRELVM vm)
{
/* Get the GameInfo */
SQUserPointer instance = nullptr;
if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, nullptr)) || instance == nullptr) return sq_throwerror(vm, "Pass an instance of a child class of GameInfo to RegisterGame");
GameInfo *info = (GameInfo *)instance;
SQInteger res = ScriptInfo::Constructor(vm, info);
if (res != 0) return res;
if (info->engine->MethodExists(info->SQ_instance, "MinVersionToLoad")) {
if (!info->engine->CallIntegerMethod(info->SQ_instance, "MinVersionToLoad", &info->min_loadable_version, MAX_GET_OPS)) return SQ_ERROR;
} else {
info->min_loadable_version = info->GetVersion();
}
/* When there is an IsSelectable function, call it. */
if (info->engine->MethodExists(info->SQ_instance, "IsDeveloperOnly")) {
if (!info->engine->CallBoolMethod(info->SQ_instance, "IsDeveloperOnly", &info->is_developer_only, MAX_GET_OPS)) return SQ_ERROR;
} else {
info->is_developer_only = false;
}
/* Try to get the API version the AI is written for. */
if (!info->CheckMethod("GetAPIVersion")) return SQ_ERROR;
if (!info->engine->CallStringMethod(info->SQ_instance, "GetAPIVersion", &info->api_version, MAX_GET_OPS)) return SQ_ERROR;
if (!CheckAPIVersion(info->api_version)) {
Debug(script, 1, "Loading info.nut from ({}.{}): GetAPIVersion returned invalid version", info->GetName(), info->GetVersion());
return SQ_ERROR;
}
/* Remove the link to the real instance, else it might get deleted by RegisterGame() */
sq_setinstanceup(vm, 2, nullptr);
/* Register the Game to the base system */
info->GetScanner()->RegisterScript(info);
return 0;
}
GameInfo::GameInfo() :
min_loadable_version(0),
is_developer_only(false)
{
}
bool GameInfo::CanLoadFromVersion(int version) const
{
if (version == -1) return true;
return version >= this->min_loadable_version && version <= this->GetVersion();
}
/* static */ void GameLibrary::RegisterAPI(Squirrel *engine)
{
/* Create the GameLibrary class, and add the RegisterLibrary function */
engine->AddClassBegin("GSLibrary");
engine->AddClassEnd();
engine->AddMethod("RegisterLibrary", &GameLibrary::Constructor, 2, "tx");
}
/* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm)
{
/* Create a new library */
GameLibrary *library = new GameLibrary();
SQInteger res = ScriptInfo::Constructor(vm, library);
if (res != 0) {
delete library;
return res;
}
/* Cache the category */
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
delete library;
return SQ_ERROR;
}
/* Register the Library to the base system */
library->GetScanner()->RegisterScript(library);
return 0;
}
|