mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@127 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
085d7ec9a3
commit
df6769a2fd
@ -1,191 +0,0 @@
|
||||
#include <nn.h>
|
||||
#include <nn/applet.h>
|
||||
#include "common.h"
|
||||
#include "sleep.h"
|
||||
#include "demo.h"
|
||||
|
||||
|
||||
extern demo::RenderSystemDrawing s_RenderSystem;
|
||||
extern nn::fnd::ExpHeap appHeap;
|
||||
extern uptr heapForGx;
|
||||
|
||||
// ファイルシステム処理と遷移やスリープ処理との排他制御に利用
|
||||
//nn::os::CriticalSection g_SleepCS;
|
||||
// HOME ボタン遷移とファイルシステム処理の排他制御に利用(手動リセット)
|
||||
nn::os::LightEvent g_TransitionEvent;
|
||||
// スリープとファイルシステム処理の排他制御に利用(手動リセット)
|
||||
nn::os::LightEvent g_AwakeEvent;
|
||||
|
||||
void restoreGraphicSetting()
|
||||
{
|
||||
// GPU レジスタ設定の復帰
|
||||
// ただし、下記は DMPGL API を使用して設定した状態の復帰のみ
|
||||
// レジスタ設定コマンドは全て再発行するべき
|
||||
nngxUpdateState(NN_GX_STATE_ALL);
|
||||
nngxValidateState(NN_GX_STATE_ALL,GL_TRUE);
|
||||
}
|
||||
|
||||
FUNCP end_func;
|
||||
void InitSysBreak(uptr adrs){
|
||||
end_func = (FUNCP)adrs;
|
||||
|
||||
SleepHandler::Initialize();
|
||||
|
||||
//g_SleepCS.Initialize();
|
||||
g_AwakeEvent.Initialize(true);
|
||||
g_TransitionEvent.Initialize(true);
|
||||
|
||||
// 起床中は常に Signal 状態にしておく
|
||||
g_AwakeEvent.Signal();
|
||||
g_TransitionEvent.Signal();
|
||||
|
||||
// アプレットライブラリに関する機能を有効にする
|
||||
nn::applet::Enable(false);
|
||||
// gx, snd, dsp 各ライブラリの Initialize 関数は applet::Enable() の後に呼ばれなければならない
|
||||
// 特に、gx の初期化である nngxInitialize 関数は、Enable() 直後の終了判定の後に行われるべき
|
||||
|
||||
// ロゴ表示時に電源ボタンが押されたなど、既に終了条件が立っていた場合、ここでアプリを終了させる
|
||||
if ( nn::applet::IsExpectedToCloseApplication() )
|
||||
{
|
||||
SleepHandler::Finalize();
|
||||
nn::Result result = nn::applet::PrepareToCloseApplication();
|
||||
NN_UTIL_PANIC_IF_FAILED( result );
|
||||
nn::applet::CloseApplication();
|
||||
}
|
||||
// グラフィックスライブラリの初期化は、以降で行わなければならない
|
||||
// 他、アプリケーションの初期化処理
|
||||
|
||||
}
|
||||
|
||||
|
||||
//終了処理
|
||||
void finish()
|
||||
{
|
||||
|
||||
SleepHandler::Finalize();//SLEEP
|
||||
//g_SleepCS.Finalize();
|
||||
g_AwakeEvent.Finalize();
|
||||
g_TransitionEvent.Finalize();
|
||||
|
||||
(*end_func)();
|
||||
|
||||
// nngxFinalize 関数呼び出しと VSync 割り込みが同時に発生すると
|
||||
// 画面が暗転したまま止まる不具合を回避するために VSync 待ちを行う
|
||||
nngxWaitVSync(NN_GX_DISPLAY_BOTH);
|
||||
s_RenderSystem.Finalize();
|
||||
|
||||
nn::fs::Finalize();
|
||||
|
||||
|
||||
appHeap.Free(reinterpret_cast<void*>(heapForGx));
|
||||
appHeap.Finalize();
|
||||
|
||||
nn::os::SetDeviceMemorySize(0);
|
||||
nn::os::SetHeapSize(0);
|
||||
|
||||
NN_LOG("End\n");
|
||||
nn::applet::PrepareToCloseApplication();
|
||||
nn::applet::CloseApplication();
|
||||
}
|
||||
|
||||
|
||||
void CheckSysBreak(){
|
||||
// スリープからの起床時は、1フレーム分の描画完了を待ってから LCD を有効にする
|
||||
if ( SleepHandler::s_IsAfterWakeUp ) {
|
||||
nn::gx::StartLcdDisplay();
|
||||
SleepHandler::s_IsAfterWakeUp = false;
|
||||
}
|
||||
|
||||
// GPU のレジスタ設定の整合性を考慮した場合、
|
||||
// 各種遷移、スリープ要求への返答は描画終了後に行うべき
|
||||
|
||||
// 本体スリープ判定
|
||||
if ( SleepHandler::IsSleepRequested() )
|
||||
{
|
||||
SleepHandler::SleepSystem();
|
||||
}
|
||||
|
||||
// 終了要求をチェック
|
||||
if ( nn::applet::IsExpectedToCloseApplication() )
|
||||
{
|
||||
finish();
|
||||
}
|
||||
|
||||
// アプリケーションの遷移処理を行う
|
||||
|
||||
// HOMEボタン処理(グラフィックスライブラリが初期化済みでなければならない)
|
||||
if ( nn::applet::IsExpectedToProcessHomeButton() )
|
||||
{
|
||||
// ここでフラグなどを判定してブロックを抜けるようにすれば HOME ボタン禁止区間を実現できる
|
||||
// nn::applet::ClearHomeButtonState() による HOME ボタンフラグ削除も必要
|
||||
|
||||
g_TransitionEvent.ClearSignal();
|
||||
|
||||
// ファイルシステム処理中は遷移を待つ
|
||||
//if ( g_SleepCS.TryEnter() )
|
||||
{
|
||||
// スリープ要求を REJECT するように
|
||||
nn::applet::DisableSleep();
|
||||
|
||||
//nngxWaitCmdlistDone();
|
||||
nn::applet::ProcessHomeButton();
|
||||
nn::applet::AppletWakeupState wState = nn::applet::WaitForStarting();
|
||||
NN_UNUSED_VAR(wState);
|
||||
|
||||
//g_SleepCS.Leave();
|
||||
g_TransitionEvent.Signal();
|
||||
|
||||
// HOME メニューからの中断やバッテリー不足の要因により
|
||||
// アプリ終了と判断された場合、アプリのメインループを抜けて終了処理へ
|
||||
if ( nn::applet::IsExpectedToCloseApplication() )
|
||||
{
|
||||
// 描画権は渡されていない
|
||||
finish();
|
||||
}
|
||||
|
||||
nn::applet::EnableSleep(true);
|
||||
|
||||
// グラフィックの設定を戻す
|
||||
restoreGraphicSetting();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 電源ボタン処理(グラフィックスライブラリが初期化済みでなければならない)
|
||||
if ( nn::applet::IsExpectedToProcessPowerButton() )
|
||||
{
|
||||
g_TransitionEvent.ClearSignal();
|
||||
|
||||
// ファイルシステム処理中は遷移を待つ
|
||||
//if ( g_SleepCS.TryEnter() )
|
||||
{
|
||||
nn::applet::DisableSleep();
|
||||
//nngxWaitCmdlistDone();
|
||||
nn::applet::ProcessPowerButton();
|
||||
nn::applet::AppletWakeupState wState = nn::applet::WaitForStarting();
|
||||
|
||||
NN_UNUSED_VAR(wState);
|
||||
|
||||
//g_SleepCS.Leave();
|
||||
g_TransitionEvent.Signal();
|
||||
|
||||
// アプリ終了と判断された場合、アプリのメインループを抜けて終了処理へ
|
||||
if ( nn::applet::IsExpectedToCloseApplication() )
|
||||
{
|
||||
// 描画権は渡されていない
|
||||
finish();
|
||||
}
|
||||
|
||||
nn::applet::EnableSleep(true);
|
||||
|
||||
// グラフィックの設定を戻す
|
||||
restoreGraphicSetting();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,369 +0,0 @@
|
||||
|
||||
#include <nn.h>
|
||||
#include <nn/fs.h>
|
||||
#include <nn/font.h>
|
||||
#include <nn/math.h>
|
||||
#include <nn/pl.h>
|
||||
#include <nn/util.h>
|
||||
|
||||
#include "demo.h"
|
||||
|
||||
const char s_ShaderBinaryFilePath[] = "rom:/nnfont_RectDrawerShader.shbin";
|
||||
|
||||
extern nn::fnd::ExpHeap appHeap;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//! @brief シェーダの初期化を行います。
|
||||
//!
|
||||
//! @param[in,out] pResource 描画用リソースを管理するオブジェクトへのポインタ。
|
||||
//---------------------------------------------------------------------------
|
||||
void*
|
||||
InitShaders(nn::font::RectDrawer* pDrawer)
|
||||
{
|
||||
const size_t ROMFS_BUFFER_SIZE = 1024 * 64;
|
||||
static char buffer[ROMFS_BUFFER_SIZE];
|
||||
|
||||
nn::fs::MountRom(16, 16, buffer, ROMFS_BUFFER_SIZE);
|
||||
nn::fs::FileReader shaderReader(s_ShaderBinaryFilePath);
|
||||
|
||||
const u32 fileSize = (u32)shaderReader.GetSize();
|
||||
|
||||
void* shaderBinary = appHeap.Allocate(fileSize);
|
||||
NN_NULL_ASSERT(shaderBinary);
|
||||
|
||||
shaderReader.Read(shaderBinary, fileSize);
|
||||
|
||||
const u32 vtxBufCmdBufSize =
|
||||
nn::font::RectDrawer::GetVertexBufferCommandBufferSize(shaderBinary, fileSize);
|
||||
void *const vtxBufCmdBuf = appHeap.Allocate(vtxBufCmdBufSize);
|
||||
NN_NULL_ASSERT(vtxBufCmdBuf);
|
||||
pDrawer->Initialize(vtxBufCmdBuf, shaderBinary, fileSize);
|
||||
|
||||
appHeap.Free(shaderBinary);
|
||||
|
||||
shaderReader.Finalize();
|
||||
nn::fs::Unmount("rom:");
|
||||
return vtxBufCmdBuf;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*
|
||||
@brief グラフィックスの初期設定を行います。
|
||||
*---------------------------------------------------------------------------*/
|
||||
void
|
||||
InitGX()
|
||||
{
|
||||
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//! @brief 描画の初期設定を行います。
|
||||
//!
|
||||
//! @param[in] width 画面の幅。
|
||||
//! @param[in] height 画面の高さ。
|
||||
//---------------------------------------------------------------------------
|
||||
void
|
||||
InitDraw(
|
||||
int width,
|
||||
int height
|
||||
)
|
||||
{
|
||||
// カラーバッファ情報
|
||||
// LCDの向きに合わせて、幅と高さを入れ替えています。
|
||||
const nn::font::ColorBufferInfo colBufInfo = { width, height, PICA_DATA_DEPTH24_STENCIL8_EXT };
|
||||
|
||||
const u32 screenSettingCommands[] =
|
||||
{
|
||||
|
||||
// ビューポートの設定
|
||||
NN_FONT_CMD_SET_VIEWPORT( 0, 0, colBufInfo.width, colBufInfo.height ),
|
||||
|
||||
// シザー処理を無効
|
||||
NN_FONT_CMD_SET_DISABLE_SCISSOR( colBufInfo ),
|
||||
|
||||
// wバッファの無効化
|
||||
// デプスレンジの設定
|
||||
// ポリゴンオフセットの無効化
|
||||
NN_FONT_CMD_SET_WBUFFER_DEPTHRANGE_POLYGONOFFSET(
|
||||
0.0f, // wScale : 0.0 でWバッファが無効
|
||||
0.0f, // depth range near
|
||||
1.0f, // depth range far
|
||||
0, // polygon offset units : 0.0 で ポリゴンオフセットが無効
|
||||
colBufInfo),
|
||||
};
|
||||
|
||||
nngxAdd3DCommand(screenSettingCommands, sizeof(screenSettingCommands), true);
|
||||
|
||||
static const u32 s_InitCommands[] =
|
||||
{
|
||||
// カリングを無効
|
||||
NN_FONT_CMD_SET_CULL_FACE( NN_FONT_CMD_CULL_FACE_DISABLE ),
|
||||
|
||||
// ステンシルテストを無効
|
||||
NN_FONT_CMD_SET_DISABLE_STENCIL_TEST(),
|
||||
|
||||
// デプステストを無効
|
||||
// カラーバッファの全ての成分を書き込み可
|
||||
NN_FONT_CMD_SET_DEPTH_FUNC_COLOR_MASK(
|
||||
false, // isDepthTestEnabled
|
||||
0, // depthFunc
|
||||
true, // depthMask
|
||||
true, // red
|
||||
true, // green
|
||||
true, // blue
|
||||
true), // alpha
|
||||
|
||||
// アーリーデプステストを無効
|
||||
NN_FONT_CMD_SET_ENABLE_EARLY_DEPTH_TEST( false ),
|
||||
|
||||
// フレームバッファアクセス制御
|
||||
NN_FONT_CMD_SET_FBACCESS(
|
||||
true, // colorRead
|
||||
true, // colorWrite
|
||||
false, // depthRead
|
||||
false, // depthWrite
|
||||
false, // stencilRead
|
||||
false), // stencilWrite
|
||||
};
|
||||
|
||||
nngxAdd3DCommand(s_InitCommands, sizeof(s_InitCommands), true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//! @brief ResFontを構築します。
|
||||
//!
|
||||
//! @param[out] pFont 構築するフォントへのポインタ。
|
||||
//! @param[in] filePath ロードするフォントリソースファイル名。
|
||||
//!
|
||||
//! @return ResFont構築の成否を返します。
|
||||
//---------------------------------------------------------------------------
|
||||
bool
|
||||
InitFont(
|
||||
nn::font::ResFont* pFont,
|
||||
void* pBuffer
|
||||
)
|
||||
{
|
||||
// フォントリソースをセットします
|
||||
bool bSuccess = pFont->SetResource(pBuffer);
|
||||
|
||||
// 描画用バッファを設定します。
|
||||
const u32 drawBufferSize = nn::font::ResFont::GetDrawBufferSize(pBuffer);
|
||||
void* drawBuffer = appHeap.Allocate(drawBufferSize, 4);
|
||||
pFont->SetDrawBuffer(drawBuffer);
|
||||
NN_NULL_ASSERT(drawBuffer);
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//! @brief ResFontを破棄します。
|
||||
//!
|
||||
//! @param[in] pFont 破棄するフォントへのポインタ。
|
||||
//---------------------------------------------------------------------------
|
||||
void
|
||||
CleanupFont(nn::font::ResFont* pFont)
|
||||
{
|
||||
// 描画用バッファの無効化
|
||||
// 描画用バッファがセットされているなら 構築時に SetDrawBuffer に渡したバッファへの
|
||||
// ポインタが返ってきます。
|
||||
void *const drawBuffer = pFont->SetDrawBuffer(NULL);
|
||||
if (drawBuffer != NULL)
|
||||
{
|
||||
appHeap.Free(drawBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//! @brief 表示文字列用バッファを確保します。
|
||||
//!
|
||||
//! @param[in] charMax 表示する文字列の最大文字数。
|
||||
//!
|
||||
//! @return 確保した表示文字列用バッファへのポインタを返します。
|
||||
//---------------------------------------------------------------------------
|
||||
nn::font::DispStringBuffer*
|
||||
AllocDispStringBuffer(int charMax)
|
||||
{
|
||||
const u32 DrawBufferSize = nn::font::CharWriter::GetDispStringBufferSize(charMax);
|
||||
void *const bufMem = appHeap.Allocate(DrawBufferSize);
|
||||
NN_NULL_ASSERT(bufMem);
|
||||
|
||||
return nn::font::CharWriter::InitDispStringBuffer(bufMem, charMax);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//! @brief 文字列表示用にモデルビュー行列と射影行列を設定します。
|
||||
//!
|
||||
//! @param[in] pDrawer RectDrawerオブジェクトへのポインタ。
|
||||
//! @param[in] width 画面の幅。
|
||||
//! @param[in] height 画面の高さ。
|
||||
//---------------------------------------------------------------------------
|
||||
void
|
||||
SetupTextCamera(
|
||||
nn::font::RectDrawer* pDrawer,
|
||||
int width,
|
||||
int height
|
||||
)
|
||||
{
|
||||
// 射影行列を正射影に設定
|
||||
{
|
||||
// 左上原点とし、Y軸とZ軸の向きが逆になるように設定します。
|
||||
nn::math::MTX44 proj;
|
||||
f32 znear = 0.0f;
|
||||
f32 zfar = -1.0f;
|
||||
f32 t = 0;
|
||||
f32 b = static_cast<f32>(width);
|
||||
f32 l = 0;
|
||||
f32 r = static_cast<f32>(height);
|
||||
nn::math::MTX44OrthoPivot(&proj, l, r, b, t, znear, zfar, nn::math::PIVOT_UPSIDE_TO_TOP);
|
||||
pDrawer->SetProjectionMtx(proj);
|
||||
}
|
||||
|
||||
// モデルビュー行列を単位行列に設定
|
||||
{
|
||||
nn::math::MTX34 mv;
|
||||
nn::math::MTX34Identity(&mv);
|
||||
pDrawer->SetViewMtxForText(mv);
|
||||
}
|
||||
}
|
||||
|
||||
nn::font::RectDrawer drawer;
|
||||
void *drawerBuf;
|
||||
nn::font::DispStringBuffer *pDrawStringBuf0;
|
||||
nn::font::DispStringBuffer *pDrawStringBuf1;
|
||||
nn::font::ResFont font;
|
||||
nn::font::TextWriter writer;
|
||||
//---------------------------------------------------------------------------
|
||||
//! @brief ASCII文字列を描画します。
|
||||
//---------------------------------------------------------------------------
|
||||
void
|
||||
shf_DrawText_0( u16 x,u16 y,char *s)
|
||||
{
|
||||
writer.SetCursor(x, y);
|
||||
|
||||
writer.StartPrint();
|
||||
(void)writer.Print(s);
|
||||
writer.EndPrint();
|
||||
drawer.BuildTextCommand(&writer);
|
||||
|
||||
|
||||
drawer.DrawBegin();
|
||||
|
||||
SetupTextCamera(&drawer, NN_GX_DISPLAY0_WIDTH, NN_GX_DISPLAY0_HEIGHT);
|
||||
writer.UseCommandBuffer();
|
||||
|
||||
drawer.DrawEnd();
|
||||
}
|
||||
|
||||
shf_DrawText_1( u16 x,u16 y,char *s)
|
||||
{
|
||||
writer.SetCursor(x, y);
|
||||
|
||||
writer.StartPrint();
|
||||
(void)writer.Print(s);
|
||||
writer.EndPrint();
|
||||
drawer.BuildTextCommand(&writer);
|
||||
|
||||
|
||||
drawer.DrawBegin();
|
||||
|
||||
SetupTextCamera(&drawer, NN_GX_DISPLAY1_WIDTH, NN_GX_DISPLAY1_HEIGHT);
|
||||
writer.UseCommandBuffer();
|
||||
|
||||
drawer.DrawEnd();
|
||||
}
|
||||
|
||||
|
||||
void shf_SetSize(f32 sz)
|
||||
{
|
||||
writer.SetScale(sz/14,sz/20);
|
||||
}
|
||||
|
||||
void shf_SetScale(f32 h,f32 v)
|
||||
{
|
||||
writer.SetScale(h,v);
|
||||
}
|
||||
|
||||
|
||||
void shf_SetFontSize(f32 sz)
|
||||
{
|
||||
writer.SetFontSize(sz);
|
||||
}
|
||||
|
||||
f32 shf_GetFontWidth()
|
||||
{
|
||||
return writer.GetFontWidth();
|
||||
}
|
||||
|
||||
f32 shf_GetFontHeight()
|
||||
{
|
||||
return writer.GetFontHeight();
|
||||
}
|
||||
|
||||
|
||||
void shf_SetColor(f32 r,f32 g,f32 b,f32 a)
|
||||
{
|
||||
writer.SetTextColor(nn::util::FloatColor(r,g,b,a));
|
||||
}
|
||||
|
||||
//初期化
|
||||
//AppHeap確保、RenderSystem.Inititの後に呼ぶ
|
||||
void SharedFontInit()
|
||||
{
|
||||
|
||||
InitGX();
|
||||
|
||||
// 共有フォントの初期化
|
||||
NN_UTIL_PANIC_IF_FAILED(nn::pl::InitializeSharedFont());
|
||||
|
||||
// 共有フォントのロードが完了するまで待機
|
||||
while (nn::pl::GetSharedFontLoadState() != nn::pl::SHARED_FONT_LOAD_STATE_LOADED)
|
||||
{
|
||||
// 共有フォントのロードに失敗していないか確認
|
||||
if (nn::pl::GetSharedFontLoadState() == nn::pl::SHARED_FONT_LOAD_STATE_FAILED)
|
||||
{
|
||||
NN_TPANIC_("failed to load shared font!\n");
|
||||
}
|
||||
nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(1));
|
||||
}
|
||||
|
||||
// 共有フォントの種類を取得
|
||||
//nn::pl::SharedFontType sharedFontType = nn::pl::GetSharedFontType();
|
||||
|
||||
// 共有フォントデータのアドレスを取得
|
||||
void* pFontBuffer = nn::pl::GetSharedFontAddress();
|
||||
|
||||
InitFont(&font, pFontBuffer);
|
||||
|
||||
// 描画リソースの構築
|
||||
drawerBuf = InitShaders(&drawer);
|
||||
|
||||
// 描画文字列用バッファの確保
|
||||
pDrawStringBuf0 = AllocDispStringBuffer(1024);
|
||||
pDrawStringBuf1 = AllocDispStringBuffer(512);
|
||||
|
||||
writer.SetDispStringBuffer(pDrawStringBuf0);
|
||||
writer.SetFont(&font);
|
||||
SetupTextCamera(&drawer, NN_GX_DISPLAY0_WIDTH, NN_GX_DISPLAY0_HEIGHT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SharedFontFinalize()
|
||||
{
|
||||
drawer.Finalize();
|
||||
|
||||
// 描画リソースの破棄
|
||||
appHeap.Free(drawerBuf);
|
||||
|
||||
// フォントの破棄
|
||||
CleanupFont(&font);
|
||||
|
||||
// 描画文字列用バッファの解放
|
||||
appHeap.Free(pDrawStringBuf1);
|
||||
appHeap.Free(pDrawStringBuf0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
End of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
Loading…
Reference in New Issue
Block a user