Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPX Patch 26.12.2023 #80

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ cmake-build-release
MechoSoma/ThirdParty/3dsftk3
MechoSoma/ThirdParty/libjpeg-turbo

efs
res_gen
res_linux
cmake-build-*
3rdparty
emscripten
CMakeFiles
*.d.ts
9 changes: 7 additions & 2 deletions MechoSoma/RUNTIME/SpriteDispatcher.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* ---------------------------- INCLUDE SECTION ----------------------------- */
#include "StdAfx.h"
#include "TGA.H"

#include "SpriteDispatcher.h"
#include "arcane_menu_d3d.h"
Expand All @@ -20,7 +21,6 @@ extern int mchA_d3dSpriteParent;
/* --------------------------- PROTOTYPE SECTION ---------------------------- */

int acsOpenResource(const char* fname,XStream& fh,int res_flag = -1);
void mchLoadTGA(XStream& fh,void** p,int& sx,int& sy,int& colors);

/* --------------------------- DEFINITION SECTION --------------------------- */

Expand Down Expand Up @@ -58,14 +58,19 @@ mchA_Sprite::~mchA_Sprite(void)

void mchA_Sprite::load(void)
{
if(!fileName) return;

int colors;
char* p;

#ifdef GPX
mchLoadTGA((std::string("RESOURCE\\ISCREEN\\") + fileName).c_str(), (void**)(&p),SizeX,SizeY,colors);
#else
XStream fh;
if(!fileName) return;

acsOpenResource(fileName,fh);
mchLoadTGA(fh,(void**)(&p),SizeX,SizeY,colors);
#endif

char* data = new char[SizeX * SizeY * 2];

Expand Down
4 changes: 4 additions & 0 deletions MechoSoma/RUNTIME/TGA.H
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ struct tgaFile
~tgaFile(void);
};

#ifdef GPX
void mchLoadTGA(const char* file,void** p,int& sx,int& sy,int& colors);
#else
void mchLoadTGA(XStream& fh,void** p,int& sx,int& sy,int& colors);
#endif

#endif // __TGA_H__
13 changes: 13 additions & 0 deletions MechoSoma/RUNTIME/arcane_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,19 @@ void mchArcaneScreenDispatcher::Quant(void)
p = p -> next;
}

#if defined(GPX) && defined(EMSCRIPTEN)
static int oldShowMode = 0;
if (oldShowMode != showMode) {
oldShowMode = showMode;
EM_ASM((
if (Module.layers) {
Module.layers.showMode($0);
}
), showMode);
}
#endif


switch(showMode){
case AE_BUILD_SCREEN:
case AE_BUILD_RACERS_SCREEN:
Expand Down
6 changes: 5 additions & 1 deletion MechoSoma/RUNTIME/intro_movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,12 @@ void mchIntroMovieDispatcher::init_texts(void)
while(p1){
mpeg_name.init();
mpeg_name < "Resource\\iScreen\\Intro_Movie\\Sound\\intro_" <= i + 1 < "_" <= id + 1 < ".mp+";
PlayMusic(mpeg_name, false);
#ifdef GPX
len = GetMusicLengthInSamples(mpeg_name);
#else
PlayMusic(mpeg_name, false);
len = GetMusicLengthInSamples();
#endif

if(len != -1)
len = len * 1000 / 44100;
Expand Down
23 changes: 22 additions & 1 deletion MechoSoma/RUNTIME/mechosoma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@

#include "Md3d.h"

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

/* ----------------------------- EXTERN SECTION ----------------------------- */

extern vrtMap* vMap;
Expand Down Expand Up @@ -272,8 +276,13 @@ int ErrHExcept = 1;
int pause;

int xgrInitFlags = XGR_EXCLUSIVE | XGR_HICOLOR;
#ifdef GPX
int xgrInitMode = MCH_1152x864; // startup videomode
int xgrGameMode = MCH_1152x864; // in-game videomode
#else
int xgrInitMode = MCH_800x600; // startup videomode
int xgrGameMode = MCH_800x600; // in-game videomode
#endif

int xgrFullscreenMode = 1;
int xgrColorDepth = 16;
Expand Down Expand Up @@ -519,7 +528,16 @@ int xtInitApplication(void)
dwScrX=1024,dwScrY=768;
break;
case MCH_1152x864:
dwScrX=1152,dwScrY=864;
#ifdef GPX
{
dwScrX = std::min<int>(gpx()->sys()->getWidth() * 1.5f, 1600);
dwScrY = dwScrX / ((float) gpx()->sys()->getWidth() / gpx()->sys()->getHeight());
xgrFullscreenMode = 0;
}
#else
dwScrX=1152,dwScrY=864;
#endif

break;
case MCH_1280x1024:
dwScrX=1280,dwScrY=1024;
Expand Down Expand Up @@ -3075,6 +3093,9 @@ void mchInitCamera(void)

void mchReInitGraph(int mode)
{
#ifdef GPX
return;
#endif
int dwScrX,GraphMode,dwScrY,FullScr,ColorBit;

gb_IVisGeneric -> GetGraphInfo(gb_URenderDevice,&dwScrX,&dwScrY,&GraphMode,&FullScr,&ColorBit);
Expand Down
10 changes: 10 additions & 0 deletions MechoSoma/RUNTIME/race.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

/* ---------------------------- INCLUDE SECTION ----------------------------- */
#if defined(GPX) && defined(EMSCRIPTEN)
#include <emscripten.h>
#endif

#include "StdAfx.h"

#include "mechosoma.h"
Expand Down Expand Up @@ -4124,8 +4128,14 @@ void mchMechosRacer::sensorIn(const SensorFieldSource* sensor)
}
break;
case IW_CREDITS_SENSOR:
#if defined(GPX) && defined(EMSCRIPTEN)
EM_ASM((
Module.showCredits();
));
#else
mch_iScreenID = ACS_CREDITS_SCR;
KeyBuf -> put(mchGetKey(MCH_KEY_EXIT),KBD_CUR_KEY_PRESSED);
#endif
break;
case IW_DOGGY_SENSOR:
if(!mchSplitScreenGame)
Expand Down
6 changes: 6 additions & 0 deletions MechoSoma/Sound/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ mchSoundEFF::~mchSoundEFF(void)
void mchSoundEFF::Load(void)
{
if(!fileName) return;
#ifdef GPX
SoundLoad(fileName,&dsPtr);
if(!freqValue)
freqValue = GetSoundFrequency(dsPtr);
#else
XStream fh(0);

if(fh.open(fileName,XS_IN)){
Expand All @@ -135,6 +140,7 @@ void mchSoundEFF::Load(void)
freqValue = GetSoundFrequency(dsPtr);
}
}
#endif
}

void mchSoundEFF::Load(const char* fname)
Expand Down
4 changes: 4 additions & 0 deletions MechoSoma/Sound/sound_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ void sndMusicPlay(int track)
static XBuffer buf;

buf.init();
#ifdef GPX
buf < "Resource\\Music\\HQ\\track";
caiiiycuk marked this conversation as resolved.
Show resolved Hide resolved
#else
buf < "RESOURCE\\MUSIC\\HQ\\track";
#endif
if(track < 10) buf < "0";
buf <= track < ".mp+";

Expand Down
5 changes: 5 additions & 0 deletions MechoSoma/Sound/sound_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ struct MusicPlayer {
virtual Status getStatus() = 0;

virtual void setVolume(int volume) = 0;

#ifdef GPX
virtual int getLengthInSamples(const char* filename) = 0;
#else
virtual int getLengthInSamples() = 0;
#endif
};

class SoundManager final {
Expand Down
2 changes: 1 addition & 1 deletion MechoSoma/VisGeneric/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct sKFrame
int attribute;

sKFrame(sKFrame *kf=0);
~sKFrame() { if(Time) delete Time; }
~sKFrame() { if(Time) delete[] Time; }
int GetNumber();
void Set(void *time,int ofs,int nKey);
inline float GetT(int number) { return (count*GetMaxTime()-Time[number-1])/(Time[number]-Time[number-1]); }
Expand Down
2 changes: 1 addition & 1 deletion MechoSoma/VisGeneric/Graph3d/Graph3d_Direct3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int cGraph3dDirect3D::GetClipRect(int *xmin,int *ymin,int *xmax,int *ymax)
}
int cGraph3dDirect3D::SetClipRect(int xmin,int ymin,int xmax,int ymax)
{
assert((xmin<=xmax)&&(ymin<=ymax)&&(xmin>=0)&&(ymin>=0)&&(xmax<xScr)&&(ymax<yScr));
assert((xmin<=xmax)&&(ymin<=ymax)&&(xmin>=0)&&(ymin>=0)&&(xmax<=xScr)&&(ymax<=yScr));
MD3DRECT rc = { xScrMin=xmin,yScrMin=ymin,xScrMax=xmax,yScrMax=ymax};
// if(SwitchRenderScene<=0) d3dSetClipRect(&rc);
return 0;
Expand Down
57 changes: 49 additions & 8 deletions MechoSoma/XTool/xgraph.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#ifdef GPX
#include <c/gamepix.h>
extern int xtMobileButton;
#endif

#include "xgraph.h"

#include <cmath>
Expand Down Expand Up @@ -656,6 +661,7 @@ void XGR_MouseFnc(SDL_Event *p)
return motion;
};

static int flag = 0;
if (p->type == SDL_MOUSEMOTION) {
const auto motion = getScaledMouseMotion();

Expand All @@ -667,37 +673,72 @@ void XGR_MouseFnc(SDL_Event *p)
XGR_MouseObj.MovementX = motion.x - x1;
XGR_MouseObj.MovementY = motion.y - y1;

XGR_MouseObj.Move(0, XGR_MouseObj.PosX, XGR_MouseObj.PosY);
XGR_MouseObj.Move(flag, XGR_MouseObj.PosX, XGR_MouseObj.PosY);
if (XGR_MouseVisible()) {
XGR_MouseRedraw();
}
} else if (p->type == SDL_MOUSEBUTTONDOWN || p->type == SDL_MOUSEBUTTONUP) {
const auto motion = getScaledMouseMotion();

#ifdef GPX
if (gpx()->sys()->isMobile()) {
p->button.button = xtMobileButton;
if (p->type == SDL_MOUSEBUTTONDOWN) {
const auto x1 = XGR_MouseObj.PosX;
const auto y1 = XGR_MouseObj.PosY;
XGR_MouseObj.InitPos(motion.x, motion.y);
XGR_MouseObj.MovementX = motion.x - x1;
XGR_MouseObj.MovementY = motion.y - y1;
XGR_MouseObj.Move(flag, XGR_MouseObj.PosX, XGR_MouseObj.PosY);
if (XGR_MouseVisible()) {
XGR_MouseRedraw();
}
}
}
#endif

int button = 0;
switch (p->button.button) {
case SDL_BUTTON_LEFT:
button = XGM_LEFT_BUTTON;
flag = 0x0001; /* MK_LBUTTON */
break;

case SDL_BUTTON_MIDDLE:
button = XGM_MIDDLE_BUTTON;
flag = 0;
break;

case SDL_BUTTON_RIGHT:
button = XGM_RIGHT_BUTTON;
flag = 0x0002; /* MK_RBUTTON */
break;

default:
break;
}

XGR_MouseInitPos(motion.x, motion.y);
if (p->type == SDL_MOUSEBUTTONDOWN) {
XGR_MousePress(button, 0, XGR_MouseObj.PosX, XGR_MouseObj.PosY);
}
if (p->type == SDL_MOUSEBUTTONUP) {
XGR_MouseUnPress(button, 0, XGR_MouseObj.PosX, XGR_MouseObj.PosY);
}
auto type = p->type;
auto fn = [type, button, motion]() {
XGR_MouseInitPos(motion.x, motion.y);
if (type == SDL_MOUSEBUTTONDOWN) {
XGR_MousePress(button, flag, XGR_MouseObj.PosX, XGR_MouseObj.PosY);
}
if (type == SDL_MOUSEBUTTONUP) {
flag = 0;
XGR_MouseUnPress(button, flag, XGR_MouseObj.PosX, XGR_MouseObj.PosY);
}
};


#ifdef GPX
if (gpx()->sys()->isMobile() && xtMobileButton != SDL_BUTTON_RIGHT) {
gpx()->async()->postTaskDelayed(fn, gamepix::Async::REGULAR, gamepix::Async::NORMAL, 128);
} else {
fn();
}
#else
fn();
#endif
}
}
4 changes: 4 additions & 0 deletions MechoSoma/XTool/xsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ void SetMusicVolume(int volume) {
}
}

#ifdef GPX
int GetMusicLengthInSamples(const char* filename) { return soundManager ? soundManager->musicPlayer().getLengthInSamples(filename) : 0; }
#else
int GetMusicLengthInSamples() { return soundManager ? soundManager->musicPlayer().getLengthInSamples() : 0; }
#endif

void XSoundQuantFnc(void) {
if (soundManager) {
Expand Down
4 changes: 4 additions & 0 deletions MechoSoma/XTool/xsound.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ void PauseMusic();
void ResumeMusic();
int GetMusicStatus();
void SetMusicVolume(int volume);
#ifdef GPX
int GetMusicLengthInSamples(const char* filename);
#else
int GetMusicLengthInSamples();
#endif

/* --------------------- CD Management --------------------- */

Expand Down
13 changes: 8 additions & 5 deletions MechoSoma/Xreal/CameraDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ void CameraDispatcher::clear(void)
flags_ = EnableControl;
input_mode = ConstInput;
clip_mode = InitClipping;
coords_spline = CameraCoordsSpline();

realtive_mouse_factor = 1024.f/XGR_MAXX;

Expand Down Expand Up @@ -1123,7 +1124,13 @@ void CameraDispatcher::setIvsCamera(const CameraCoords& coords)

Mat3f R = coords.rot();

Vect3f camera_position = R*vg + Vect3f(0, -coords.CenteringDelta*coords.cameraDistance, coords.cameraDistance);
auto aspect = std::min<float>(2.22f, XGR_Obj.ScreenY > 0 ? (float) XGR_Obj.ScreenX / XGR_Obj.ScreenY : 1.33f);
#ifdef GPX
auto zOffset = (aspect - 1.33f) / (2.22f - 1.33f) * 100;
#else
auto zOffset = 0;
#endif
Vect3f camera_position = R*vg + Vect3f(0, -coords.CenteringDelta*coords.cameraDistance, coords.cameraDistance + zOffset);
camera_position.negate();

MatXf MC(R, camera_position);
Expand Down Expand Up @@ -1402,10 +1409,6 @@ CameraCoords CameraDispatcher::stopTimeInput()
else{
Vect3f pv, pe, pe0(XGR_MouseObj.PosX, XGR_MouseObj.PosY, 0);

// TODO: @caiiiycuk investigate this
#ifdef WTF
_controlfp(_PC_53, _MCW_PC);
#endif
if(hCamera > stop_time_hCamera){
Vect2f ScrSize = ((cRenderDevice*)ivsRenderDevice) -> GetSize();
Vect2f Center = ivsCamera -> GetCenter()*ScrSize;
Expand Down
Loading
Loading