Skip to content

Commit

Permalink
Merge pull request KD-lab-Open-Source#117 from caiiiycuk/html5
Browse files Browse the repository at this point in the history
GPX patch and sokol updates
  • Loading branch information
IonAgorria authored Feb 9, 2024
2 parents 9b447e8 + dddd7f1 commit f9da5a4
Show file tree
Hide file tree
Showing 36 changed files with 2,302 additions and 651 deletions.
9 changes: 9 additions & 0 deletions Source/Game/GameContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ void findGameContent() {
//Path stored in settings from last run
if (settingsPath) paths.emplace_back(settingsPath);

#ifdef GPX
paths.clear();
#ifdef EMSCRIPTEN
paths.emplace_back("/");
#else
paths.emplace_back("./");
#endif
#endif

//Check paths for Resource dir
std::set<std::string> scannedPaths;
for (std::string rootPathStr : paths) {
Expand Down
8 changes: 8 additions & 0 deletions Source/Game/PerimeterDataChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ extern int terDrawMeshShadow;
extern int terShadowType;
extern int terMipMapLevel;
extern int terShowTips;
#ifdef GPX
extern const int terResizableWindow;
#else
extern int terResizableWindow;
#endif
extern int applicationRunBackground;

extern float terNearDistanceLOD;
Expand All @@ -38,8 +42,10 @@ void PerimeterDataChannelLoad()
IniManager ini_no_check("Perimeter.ini", false);

//GraphicsSection
#ifndef GPX
terFullScreen = ini.getInt("Graphics","FullScreen");
check_command_line_parameter("FullScreen", terFullScreen);
#endif
terScreenIndex = -1;
ini_no_check.getInt("Graphics", "ScreenIndex", terScreenIndex);
terScreenRefresh = ini_no_check.getInt("Graphics", "ScreenRefresh");
Expand All @@ -51,8 +57,10 @@ void PerimeterDataChannelLoad()
}
if (0 < ScreenSizeX) terScreenSizeX = ScreenSizeX;
if (0 < ScreenSizeY) terScreenSizeY = ScreenSizeY;
#ifndef GPX
ini_no_check.getInt("Graphics","ResizableWindow", terResizableWindow);
check_command_line_parameter("ResizableWindow", terResizableWindow);
#endif
terBitPerPixel = ini.getInt("Graphics","BPP");
terMapLevelLOD = ini.getInt("Graphics","MapLevelLOD");

Expand Down
43 changes: 42 additions & 1 deletion Source/Game/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include <SDL_image.h>
#include <SDL_vulkan.h>

#ifdef GPX
#include <c/gamepix.h>
#endif

#ifdef _WIN32
#include <commdlg.h>
#endif
Expand Down Expand Up @@ -73,8 +77,13 @@ cTileMap* terMapPoint = NULL;
int terBitPerPixel = 16;
int terScreenRefresh = 0;
int terScreenIndex = 0;
#ifdef GPX
constexpr int terFullScreen = 0;
constexpr int terResizableWindow = 0;
#else
int terFullScreen = 0;
int terResizableWindow = 1;
#endif
int terScreenSizeX = 800;
int terScreenSizeY = 600;
float terGraphicsGamma = 1;
Expand Down Expand Up @@ -564,6 +573,16 @@ cInterfaceRenderDevice* SetGraph()

cInterfaceRenderDevice *IRenderDevice = CreateIRenderDevice(deviceSelection);

#ifdef GPX
terBitPerPixel = 32;
terScreenSizeX = gpx()->sys()->getWidth();
terScreenSizeY = gpx()->sys()->getHeight();
if (terScreenSizeY < 720) {
terScreenSizeY = 720;
terScreenSizeX = 720.0f * gpx()->sys()->getWidth() / gpx()->sys()->getHeight();
}
int ModeRender = RENDERDEVICE_MODE_RGB32 | RENDERDEVICE_MODE_WINDOW;
#else
int ModeRender=0;
if (!isTrueFullscreen()) {
ModeRender |= RENDERDEVICE_MODE_WINDOW;
Expand All @@ -573,6 +592,7 @@ cInterfaceRenderDevice* SetGraph()
} else {
ModeRender |= RENDERDEVICE_MODE_RGB16;
}
#endif

// if(HTManager::instance()->IsUseHT())
ModeRender |= RENDERDEVICE_MODE_MULTITHREAD;
Expand Down Expand Up @@ -871,7 +891,7 @@ void show_help() {
}

//------------------------------
#ifndef _WIN32
#if !defined(_WIN32) && !defined(GPX)
int main(int argc, char *argv[]) {
//Call SDL main init
SDL_SetMainReady();
Expand Down Expand Up @@ -1001,6 +1021,27 @@ int SDL_main(int argc, char *argv[])
WaitMessage();
#endif
}

#ifdef GPX
static bool gpx_ready = false;
if (!gpx_ready) {
gpx_ready = false;
#ifdef EMSCRIPTEN
EM_ASM(({
if (!document.pointerLockElement) {
Module["canvas"].addEventListener("pointerdown", () => {
Module["canvas"].requestPointerLock().catch((e) => console.error("Can't lock mouse", e));
});
}
}));
#endif
gpx()->sys()->mainReady(true);
}
gpx()->async()->runNextTask();
#ifdef EMSCRIPTEN
emscripten_sleep(0);
#endif
#endif
}

delete runtime_object;
Expand Down
4 changes: 4 additions & 0 deletions Source/Game/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ extern class cScene* terScene;
extern class cUnkLight* terLight;
extern class cTileMap* terMapPoint;

#ifdef GPX
extern const int terFullScreen;
#else
extern int terFullScreen;
#endif
extern int terScreenSizeX;
extern int terScreenSizeY;
extern int terBitPerPixel;
Expand Down
121 changes: 88 additions & 33 deletions Source/Game/Texts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,72 @@
#include "GameContent.h"
#include "qd_textdb.h"

const char* CREDITS_PERIMETER_RUSSIAN = R"(ПЕРИМЕТР
#ifdef GPX
constexpr char* HEADER_RUS = R"(
&FFFFBBПосвящено памяти
Андрея "КранК" Кузьмина
1971 - 2022
&66CCFFGamePix
gamepix.com&FFFFFF
&CCCCFFВеб версия&FFFFFF
Александр "caiiiycuk" Гурьянов
&66CCFFК-Д ЛАБ
kdlab.com&FFFFFF
Андрей "КранК" Кузьмин)";

constexpr char* HEADER_ENG = R"(
&FFFFBBDedicated to the memory of
Andrey "KranK" Kuzmin
1971 - 2022
&66CCFFGamePix
gamepix.com&FFFFFF
&CCCCFFWeb Version&FFFFFF
Alexander "caiiiycuk" Guryanov
&66CCFFK-D LAB
kdlab.com&FFFFFF
Andrey "KranK" Kuzmin)";
#else
constexpr char* HEADER_RUS = R"(
&66CCFFК-Д ЛАБ
kdlab.com&FFFFFF
&FFFFBBПосвящено памяти
Андрея "КранК" Кузьмина
1971 - 2022
1971 - 2022)";

constexpr char* HEADER_ENG = R"(
&66CCFFK-D LAB
kdlab.com&FFFFFF
&FFFFBBDedicated to the memory of
Andrey "KranK" Kuzmin
1971 - 2022)";
#endif

constexpr char* CREDITS_PERIMETER_TITLE_RUSSIAN = "ПЕРИМЕТР";
constexpr char* CREDITS_PERIMETER_RUSSIAN =
R"(
&CCCCFFПродюсер&FFFFFF
Игровая концепция и вселенная,
сценарий
Юлия "Ylitka" Шапошникова
Юлия "Ylitka" Новикова (Шапошникова)
&CCCCFFГлавный гейм-дизайнер&FFFFFF
Дизайн миссий, AI
Expand Down Expand Up @@ -121,18 +174,13 @@ Copyright (C) 1994-2023 Xiph.Org
)"; //END CREDITS_PERIMETER_RUSSIAN

const char* CREDITS_PERIMETER_ET_RUSSIAN = R"(ПЕРИМЕТР: Завет Императора
&66CCFFК-Д ЛАБ
kdlab.com&FFFFFF
&FFFFBBПосвящено памяти
Андрея "КранК" Кузьмина
1971 - 2022
constexpr char* CREDITS_PERIMETER_ET_TITLE_RUSSIAN = "ПЕРИМЕТР: Завет Императора";
constexpr char* CREDITS_PERIMETER_ET_RUSSIAN =
R"(
&CCCCFFКонцепт-дизайнер&FFFFFF
Игровая концепция и вселенная
Юлия "Ylitka" Шапошникова
Юлия "Ylitka" Новикова (Шапошникова)
&CCCCFFИсполнительный продюсер &FFFFFF
Гейм-дизайн, дизайн миссий, AI
Expand Down Expand Up @@ -349,19 +397,14 @@ github.com/KD-lab-Open-Source
)"; //END CREDITS_COMMON_RUSSIAN

const char* CREDITS_PERIMETER_ENGLISH = R"(PERIMETER
&66CCFFK-D LAB
kdlab.com&FFFFFF
&FFFFBBDedicated to the memory of
Andrey "KranK" Kuzmin
1971 - 2022
constexpr char* CREDITS_PERIMETER_TITLE_ENGLISH = "PERIMETER";
constexpr char* CREDITS_PERIMETER_ENGLISH = "PERIMETER"
R"(
&CCCCFFProducer&FFFFFF
Game Concept, Game Universe,
Scenarios
Yulia "Ylitka" Shaposhnikova
Yulia "Ylitka" Novikova (Shaposhnikova)
&CCCCFFLead Game Designer&FFFFFF
Missions, AI
Expand Down Expand Up @@ -459,18 +502,13 @@ Copyright (C) 1994-2023 Xiph.Org.
)"; //END CREDITS_PERIMETER_ENGLISH

const char* CREDITS_PERIMETER_ET_ENGLISH = R"(PERIMETER: Emperor's Testament
&66CCFFK-D LAB
kdlab.com&FFFFFF
&FFFFBBDedicated to the memory of
Andrey "KranK" Kuzmin
1971 - 2022
constexpr char* CREDITS_PERIMETER_ET_TITLE_ENGLISH = "PERIMETER: Emperor's Testament";
constexpr char* CREDITS_PERIMETER_ET_ENGLISH = "PERIMETER: Emperor's Testament"
R"(
&CCCCFFConcept-designer&FFFFFF
Game concept, Game universe
Yulia "Ylitka" Shaposhnikova
Yulia "Ylitka" Novikova (Shaposhnikova)
&CCCCFFExecutive Producer&FFFFFF
Game Design, Missions, AI
Expand Down Expand Up @@ -691,10 +729,27 @@ void qdTextDB::load_replacement_texts(const std::string& locale) {
//Credits
std::string credits = "Interface.Credits=";
bool russian = startsWith(locale, "russian");
if (terGameContentSelect == PERIMETER_ET) {
credits += russian ? CREDITS_PERIMETER_ET_RUSSIAN : CREDITS_PERIMETER_ET_ENGLISH;
if (russian) {
if (terGameContentSelect == PERIMETER_ET) {
credits += CREDITS_PERIMETER_ET_TITLE_RUSSIAN;
credits += HEADER_RUS;
credits += CREDITS_PERIMETER_ET_RUSSIAN;
} else {
credits += CREDITS_PERIMETER_TITLE_RUSSIAN;
credits += HEADER_RUS;
credits += CREDITS_PERIMETER_RUSSIAN;
}
} else {
credits += russian ? CREDITS_PERIMETER_RUSSIAN : CREDITS_PERIMETER_ENGLISH;
if (terGameContentSelect == PERIMETER_ET) {
credits += CREDITS_PERIMETER_ET_TITLE_ENGLISH;
credits += HEADER_ENG;
credits += CREDITS_PERIMETER_ET_ENGLISH;
} else {
credits += CREDITS_PERIMETER_TITLE_ENGLISH;
credits += HEADER_ENG;
credits += CREDITS_PERIMETER_ENGLISH;
}

}
credits += russian ? CREDITS_COMMON_RUSSIAN : CREDITS_COMMON_ENGLISH;
load_lines({credits}, true, locale);
Expand Down
2 changes: 1 addition & 1 deletion Source/Game/VideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bool VideoPlayer::Init(const char* path) {
const int samples = SNDDeviceFrequency() / 10;
size_t buf_len = SNDformatSampleSize(SNDDeviceFormat()) * SNDDeviceChannels() * samples;
void* buf = SDL_calloc(buf_len, 1);
sample->loadRawData(static_cast<uint8_t*>(buf), buf_len, false);
sample->loadRawData(static_cast<uint8_t*>(buf), buf_len, false, path_str);
}

#if 0 && defined(PERIMETER_DEBUG)
Expand Down
9 changes: 9 additions & 0 deletions Source/Render/sokol/SokolRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "RenderTracker.h"
#include <SDL_hints.h>

#ifdef SOKOL_GL
#include <SDL_opengl.h>
#endif

cSokolRender::cSokolRender() = default;

cSokolRender::~cSokolRender() {
Expand Down Expand Up @@ -120,6 +124,7 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres
if (sdlGlContext == nullptr) {
ErrH.Abort("Error creating SDL GL Context", XERR_CRITICAL, 0, SDL_GetError());
}
printf("GPU vendor: %s, renderer: %s\n", glGetString(GL_VENDOR), glGetString(GL_RENDER));
#endif

//Call sokol gfx setup
Expand All @@ -142,7 +147,11 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres
uint8_t* buf = new uint8_t[buf_len];
memset(buf, 0xFF, buf_len);
imgdesc->data.subimage[0][0] = { buf, buf_len };
#ifdef GPX
emptyTexture = new SokolTexture2D(imgdesc, false);
#else
emptyTexture = new SokolTexture2D(imgdesc);
#endif

RenderSubmitEvent(RenderEvent::INIT, "Sokol done");
return UpdateRenderMode();
Expand Down
Loading

0 comments on commit f9da5a4

Please sign in to comment.