Skip to content
Open
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
1 change: 0 additions & 1 deletion platforms/android/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ void android_main(struct android_app* state) {
engine.androidApp = state;

engine.ninecraftApp = new NinecraftApp;
engine.ninecraftApp->m_pPlatform = &g_AppPlatform;

while (1)
{
Expand Down
1 change: 0 additions & 1 deletion platforms/ios/NBCViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ - (void)initView
}
App *app = self->_app;

app->m_pPlatform = self->_context->platform;
app->init();

/*var1 = app->field_10;
Expand Down
21 changes: 12 additions & 9 deletions platforms/sdl/sdl1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ typedef AppPlatform_sdl1_desktop UsedAppPlatform;

static float g_fPointToPixelScale = 1.0f;

UsedAppPlatform* g_pAppPlatform;
NinecraftApp* g_pApp;

SDL_Surface* screen = NULL;

static UsedAppPlatform* getPlatform()
{
return static_cast<UsedAppPlatform*>(AppPlatform::singleton());
}

static void initPlatform()
{
#ifdef XENON
Expand Down Expand Up @@ -155,7 +159,7 @@ static void handle_events()
}
}

g_pAppPlatform->handleKeyEvent(event);
getPlatform()->handleKeyEvent(event);
break;
}
case SDL_JOYBUTTONDOWN:
Expand All @@ -166,7 +170,7 @@ static void handle_events()
{
g_pApp->pauseGame() || g_pApp->resumeGame();
}
g_pAppPlatform->handleControllerButtonEvent(event.jbutton.which, event.jbutton.button, event.jbutton.state);
getPlatform()->handleControllerButtonEvent(event.jbutton.which, event.jbutton.button, event.jbutton.state);
break;
}
case SDL_MOUSEBUTTONDOWN:
Expand All @@ -186,11 +190,11 @@ static void handle_events()
float x = event.motion.x * scale;
float y = event.motion.y * scale;
Mouse::feed(MOUSE_BUTTON_NONE, false, x, y);
g_pAppPlatform->setMouseDiff(event.motion.xrel * scale, event.motion.yrel * scale);
getPlatform()->setMouseDiff(event.motion.xrel * scale, event.motion.yrel * scale);
break;
}
case SDL_JOYAXISMOTION:
g_pAppPlatform->handleControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
getPlatform()->handleControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
break;
case SDL_VIDEORESIZE:
{
Expand Down Expand Up @@ -243,7 +247,7 @@ static void main_loop()
{
g_pApp->saveOptions();
delete g_pApp;
delete g_pAppPlatform;
delete getPlatform();
teardown();
exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -292,11 +296,10 @@ int main(int argc, char* argv[])
createFolderIfNotExists(storagePath.c_str());

//LOG_I("Initializing AppPlatform...");
g_pAppPlatform = new UsedAppPlatform(storagePath, screen);
g_pAppPlatform->m_externalStorageDir = storagePath;
UsedAppPlatform* appPlatform = new UsedAppPlatform(storagePath, screen);
appPlatform->m_externalStorageDir = storagePath;
//LOG_I("Initializing NinecraftApp...");
g_pApp = new NinecraftApp;
g_pApp->m_pPlatform = g_pAppPlatform;
g_pApp->init();

resize();
Expand Down
27 changes: 15 additions & 12 deletions platforms/sdl/sdl2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ typedef AppPlatform_sdl2_desktop UsedAppPlatform;

static float g_fPointToPixelScale = 1.0f;

UsedAppPlatform *g_pAppPlatform;
NinecraftApp *g_pApp;

SDL_Window *window = NULL;
SDL_GLContext glContext = NULL;

static UsedAppPlatform* getPlatform()
{
return static_cast<UsedAppPlatform*>(AppPlatform::singleton());
}

static void preInitGraphics()
{
#if MCE_GFX_API_OGL
Expand Down Expand Up @@ -194,7 +198,7 @@ static void handle_events()
g_pApp->handleCharInput('\b');
}

if (g_pAppPlatform->controlPressed())
if (getPlatform()->controlPressed())
{
// Copy and pasting
if (event.key.keysym.sym == SDLK_v && event.key.state == SDL_PRESSED)
Expand All @@ -204,7 +208,7 @@ static void handle_events()
}
}

g_pAppPlatform->handleKeyEvent(event);
getPlatform()->handleKeyEvent(event);
break;
}
case SDL_CONTROLLERBUTTONDOWN:
Expand All @@ -215,7 +219,7 @@ static void handle_events()
{
g_pApp->pauseGame() || g_pApp->resumeGame();
}
g_pAppPlatform->handleControllerButtonEvent(event.cbutton.which, event.cbutton.button, event.cbutton.state);
getPlatform()->handleControllerButtonEvent(event.cbutton.which, event.cbutton.button, event.cbutton.state);
break;
}
case SDL_MOUSEBUTTONDOWN:
Expand All @@ -242,7 +246,7 @@ static void handle_events()
float y = event.motion.y * scale;
Multitouch::feed(MOUSE_BUTTON_NONE, false, x, y, 0);
Mouse::feed(MOUSE_BUTTON_NONE, false, x, y);
g_pAppPlatform->setMouseDiff(event.motion.xrel * scale, event.motion.yrel * scale);
getPlatform()->setMouseDiff(event.motion.xrel * scale, event.motion.yrel * scale);
}
break;
}
Expand All @@ -255,7 +259,7 @@ static void handle_events()
break;
}
case SDL_CONTROLLERAXISMOTION:
g_pAppPlatform->handleControllerAxisEvent(event.caxis.which, event.caxis.axis, event.caxis.value);
getPlatform()->handleControllerAxisEvent(event.caxis.which, event.caxis.axis, event.caxis.value);
break;
case SDL_FINGERDOWN:
case SDL_FINGERUP:
Expand All @@ -280,10 +284,10 @@ static void handle_events()
break;
}
case SDL_CONTROLLERDEVICEADDED:
g_pAppPlatform->gameControllerAdded(event.cdevice.which);
getPlatform()->gameControllerAdded(event.cdevice.which);
break;
case SDL_CONTROLLERDEVICEREMOVED:
g_pAppPlatform->gameControllerRemoved(event.cdevice.which);
getPlatform()->gameControllerRemoved(event.cdevice.which);
break;
case SDL_WINDOWEVENT:
{
Expand Down Expand Up @@ -355,7 +359,7 @@ static EM_BOOL main_loop(double time, void *user_data)
{
g_pApp->saveOptions();
delete g_pApp;
delete g_pAppPlatform;
delete getPlatform();
teardown();
// Stop Looping
return EM_FALSE;
Expand Down Expand Up @@ -438,10 +442,9 @@ int main(int argc, char *argv[])
createFolderIfNotExists(storagePath.c_str());

// Start MCPE
g_pAppPlatform = new UsedAppPlatform(storagePath, window);
g_pAppPlatform->m_externalStorageDir = storagePath;
UsedAppPlatform* appPlatform = new UsedAppPlatform(storagePath, window);
appPlatform->m_externalStorageDir = storagePath;
g_pApp = new NinecraftApp;
g_pApp->m_pPlatform = g_pAppPlatform;
g_pApp->init();

// Set Size
Expand Down
1 change: 0 additions & 1 deletion platforms/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
goto _cleanup;

g_pApp = new NinecraftApp;
g_pApp->m_pPlatform = &g_AppPlatform;

// Storage Directory
{
Expand Down
1 change: 0 additions & 1 deletion platforms/xdk360/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void __cdecl main()
goto _cleanup;

g_pApp = new NinecraftApp;
g_pApp->m_pPlatform = &g_AppPlatform;
g_AppPlatform.m_externalStorageDir = "savedrive:";

// initialize the app
Expand Down
5 changes: 0 additions & 5 deletions source/client/app/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class App : public AppPlatformListener
App()
{
m_bWantToQuit = false;
m_pPlatform = nullptr;
}

public:
Expand All @@ -30,8 +29,6 @@ class App : public AppPlatformListener
void destroy();
void draw();
void loadState(void*, int);
AppPlatform* platform() { return m_pPlatform; }
const AppPlatform* platform() const { return m_pPlatform; }
void quit();
void saveState(void**, int);
bool wantToQuit();
Expand All @@ -43,7 +40,5 @@ class App : public AppPlatformListener
int field_8;
int field_C;
int field_10;

AppPlatform* m_pPlatform;
};

22 changes: 11 additions & 11 deletions source/client/app/Minecraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void Minecraft::_reloadInput()
{
m_pInputHolder = new CustomInputHolder(
new KeyboardInput(getOptions()),
new MouseTurnInput(this),
new MouseTurnInput(),
new MouseBuildInput()
);
}
Expand All @@ -224,7 +224,7 @@ void Minecraft::_reloadInput()
int Minecraft::getLicenseId()
{
if (m_licenseID < 0)
m_licenseID = m_pPlatform->checkLicense();
m_licenseID = AppPlatform::singleton()->checkLicense();

return m_licenseID;
}
Expand All @@ -244,7 +244,7 @@ void Minecraft::releaseMouse()
// the mouse handler, but we don't have access to the platform
// from there!
recenterMouse();
platform()->setMouseGrabbed(false);
AppPlatform::singleton()->setMouseGrabbed(false);
}

void Minecraft::grabMouse()
Expand All @@ -261,15 +261,15 @@ void Minecraft::grabMouse()
if (useController() || isTouchscreen())
return; // don't actually try to grab the mouse

platform()->setMouseGrabbed(true);
AppPlatform::singleton()->setMouseGrabbed(true);
}

void Minecraft::recenterMouse()
{
if (useController() || isTouchscreen())
return;

platform()->recenterMouse();
AppPlatform::singleton()->recenterMouse();
}

void Minecraft::setScreen(Screen* pScreen)
Expand Down Expand Up @@ -343,13 +343,13 @@ void Minecraft::setScreen(Screen* pScreen)

void Minecraft::saveOptions()
{
if (platform()->hasFileSystemAccess())
if (AppPlatform::singleton()->hasFileSystemAccess())
getOptions()->save().join();
}

void Minecraft::saveOptionsAsync()
{
if (platform()->hasFileSystemAccess())
if (AppPlatform::singleton()->hasFileSystemAccess())
getOptions()->save();
}

Expand Down Expand Up @@ -383,7 +383,7 @@ bool Minecraft::useSplitControls() const

bool Minecraft::useController() const
{
return m_pPlatform->hasGamepad() && getOptions()->m_bUseController.get();
return AppPlatform::singleton()->hasGamepad() && getOptions()->m_bUseController.get();
}

void Minecraft::setGameMode(GameType gameType)
Expand Down Expand Up @@ -576,7 +576,7 @@ void Minecraft::tickInput()
{
// @HACK: on SDL1, we don't recenter the mouse every tick, meaning the user can
// unintentionally click the hotbar while swinging their fist
if (platform()->getRecenterMouseEveryTick() || m_pScreen)
if (AppPlatform::singleton()->getRecenterMouseEveryTick() || m_pScreen)
m_pGui->handleClick(1, Mouse::getX(), Mouse::getY());
}

Expand Down Expand Up @@ -697,7 +697,7 @@ void Minecraft::tickMouse()
if (useController() || isTouchscreen())
return; // don't actually try to recenter the mouse

if (platform()->getRecenterMouseEveryTick()) // just for SDL1
if (AppPlatform::singleton()->getRecenterMouseEveryTick()) // just for SDL1
recenterMouse();
}

Expand Down Expand Up @@ -896,7 +896,7 @@ void Minecraft::update()
{
m_timer.advanceTime(isGamePaused() && m_pLevel);

platform()->tick();
AppPlatform::singleton()->tick();

if (m_pRakNetInstance && m_pNetEventCallback)
{
Expand Down
22 changes: 11 additions & 11 deletions source/client/app/NinecraftApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void NinecraftApp::_initOptions()
// Must be loaded before options, certain options states are forced based on this
_reloadPatchData();

if (platform()->hasFileSystemAccess())
m_pOptions = new Options(this, platform()->m_externalStorageDir);
if (AppPlatform::singleton()->hasFileSystemAccess())
m_pOptions = new Options(this, AppPlatform::singleton()->m_externalStorageDir);
else
m_pOptions = new Options(this);

Expand Down Expand Up @@ -101,8 +101,8 @@ void NinecraftApp::_initRenderMaterials()

void NinecraftApp::_initInput()
{
m_bIsTouchscreen = platform()->isTouchscreen();
getOptions()->m_bUseController.set(platform()->hasGamepad());
m_bIsTouchscreen = AppPlatform::singleton()->isTouchscreen();
getOptions()->m_bUseController.set(AppPlatform::singleton()->hasGamepad());
getOptions()->loadControls();
_reloadInput();
}
Expand Down Expand Up @@ -195,7 +195,7 @@ void NinecraftApp::_initAll()
#ifdef DEMO
m_pLevelStorageSource = new MemoryLevelStorageSource;
#else
m_pLevelStorageSource = new ExternalFileLevelStorageSource(platform()->m_externalStorageDir);
m_pLevelStorageSource = new ExternalFileLevelStorageSource(AppPlatform::singleton()->m_externalStorageDir);
#endif

_initInput();
Expand All @@ -207,8 +207,8 @@ void NinecraftApp::_initAll()
m_pParticleEngine = new ParticleEngine(m_pLevel, m_pTextures);
m_pUser = new User(getOptions()->m_playerName.get(), "");

platform()->initSoundSystem();
m_pSoundEngine = new SoundEngine(platform()->getSoundSystem(), SOUND_MAX_DISTANCE);
AppPlatform::singleton()->initSoundSystem();
m_pSoundEngine = new SoundEngine(AppPlatform::singleton()->getSoundSystem(), SOUND_MAX_DISTANCE);
m_pSoundEngine->init(getOptions());

Language::singleton().init(getOptions());
Expand Down Expand Up @@ -334,16 +334,16 @@ void NinecraftApp::setupRenderer()

void NinecraftApp::onGraphicsReset()
{
platform()->_fireAppSuspended();
platform()->_fireAppResumed();
AppPlatform::singleton()->_fireAppSuspended();
AppPlatform::singleton()->_fireAppResumed();
}

void NinecraftApp::teardown()
{
teardownRenderer();
Resource::teardownLoaders();
// Stop our SoundSystem before we nuke our sound buffers and cause it to implode
platform()->getSoundSystem()->stopEngine();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you create a platform() function within the scope of the CPP file? I like having the shorthand here. of all of the files, this is where AppPlatform is used the most afaik

AppPlatform::singleton()->getSoundSystem()->stopEngine();
}

void NinecraftApp::teardownRenderer()
Expand All @@ -367,7 +367,7 @@ void NinecraftApp::update()

if (getOptions()->m_bUseController.get())
{
GameControllerHandler* pControllerHandler = platform()->getGameControllerHandler();
GameControllerHandler* pControllerHandler = AppPlatform::singleton()->getGameControllerHandler();
if (pControllerHandler)
{
pControllerHandler->refresh();
Expand Down
Loading
Loading