Skip to content

Commit

Permalink
Merge pull request #39 from roblabla/SupervisorChain
Browse files Browse the repository at this point in the history
Implement Supervisor chain
  • Loading branch information
roblabla authored Dec 12, 2023
2 parents 060c02b + c8ddd7c commit f5d3495
Show file tree
Hide file tree
Showing 22 changed files with 1,155 additions and 239 deletions.
21 changes: 19 additions & 2 deletions config/implemented.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
AsciiManager::AsciiManager
AsciiManager::OnUpdate
AsciiManager::OnDrawMenus
AsciiManager::OnDrawPopups
AsciiManager::RegisterChain
AsciiManager::AddedCallback
AsciiManager::InitializeVms
AsciiManager::DeletedCallback
AsciiManager::CutChain
AsciiManager::AddString
AnmManager::CopySurfaceToBackBuffer
AnmManager::LoadAnm
AnmManager::LoadSurface
AnmManager::ReleaseSurface
ChainElem::ChainElem
ChainElem::~ChainElem
ChainElem::Allocate
Chain::CreateElem
Chain::ReleaseSingleChain
Chain::Release
Chain::Cut
Expand All @@ -26,7 +40,10 @@ DebugPrint
DebugPrint2
FileSystem::OpenPath
FileSystem::WriteDataToFile
GameContext::Parse
Supervisor::AddedCallback
Supervisor::LoadPbg3
Supervisor::RegisterChain
Supervisor::Parse
InitD3dDevice
InitD3dRendering
Clear
Expand Down
5 changes: 4 additions & 1 deletion scripts/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,19 @@ def configure(build_type):
)

cxx_sources = [
"AsciiManager",
"main",
"Chain",
"FileSystem",
"GameContext",
"Supervisor",
"GameErrorContext",
"GameWindow",
"MidiOutput",
"SoundPlayer",
"Stage",
"AnmManager",
"GameManager",
"Rng",
"utils",
]

Expand Down
252 changes: 252 additions & 0 deletions src/AnmManager.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,265 @@
#include "AnmManager.hpp"
#include "FileSystem.hpp"
#include "GameErrorContext.hpp"
#include "Supervisor.hpp"
#include "i18n.hpp"

AnmTimer::AnmTimer()
{
// TODO: stub
}

void AnmVm::Initialize()
{
// TODO: Stub
}

AnmVm::AnmVm()
{
// TODO: stub
}

AnmManager::AnmManager()
{
}
AnmManager::~AnmManager()
{
}

void AnmManager::SetupVertexBuffer()
{
// TODO: stub
}

void AnmManager::ReleaseD3dSurfaces(void)
{
}

ZunResult AnmManager::LoadSurface(i32 surfaceIdx, char *path)
{
if (this->surfaces[surfaceIdx] != NULL)
{
this->ReleaseSurface(surfaceIdx);
}
u8 *data = FileSystem::OpenPath(path, 0);
if (data == NULL)
{
GameErrorContextFatal(&g_GameErrorContext, TH_ERR_CANNOT_BE_LOADED, path);
return ZUN_ERROR;
}

LPDIRECT3DSURFACE8 surface;
if (g_Supervisor.d3dDevice->CreateImageSurface(0x280, 0x400, g_Supervisor.presentParameters.BackBufferFormat,
&surface) != D3D_OK)
{
return ZUN_ERROR;
}

if (D3DXLoadSurfaceFromFileInMemory(surface, NULL, NULL, data, g_LastFileSize, NULL, D3DX_FILTER_NONE, 0,
&this->surfaceSourceInfo[surfaceIdx]) != D3D_OK)
{
goto fail;
}
if (g_Supervisor.d3dDevice->CreateRenderTarget(this->surfaceSourceInfo[surfaceIdx].Width,
this->surfaceSourceInfo[surfaceIdx].Height,
g_Supervisor.presentParameters.BackBufferFormat, D3DMULTISAMPLE_NONE,
TRUE, &this->surfaces[surfaceIdx]) != D3D_OK)
{
goto fail;
}
if (g_Supervisor.d3dDevice->CreateImageSurface(
this->surfaceSourceInfo[surfaceIdx].Width, this->surfaceSourceInfo[surfaceIdx].Height,
g_Supervisor.presentParameters.BackBufferFormat, &this->surfaces[surfaceIdx]) != D3D_OK)
{
goto fail;
}
if (g_Supervisor.d3dDevice->CreateImageSurface(
this->surfaceSourceInfo[surfaceIdx].Width, this->surfaceSourceInfo[surfaceIdx].Height,
g_Supervisor.presentParameters.BackBufferFormat, &this->surfacesBis[surfaceIdx]) != D3D_OK)
{
goto fail;
}

if (D3DXLoadSurfaceFromSurface(this->surfaces[surfaceIdx], NULL, NULL, surface, NULL, NULL, D3DX_FILTER_NONE, 0) !=
D3D_OK)
{
goto fail;
}

if (D3DXLoadSurfaceFromSurface(this->surfacesBis[surfaceIdx], NULL, NULL, surface, NULL, NULL, D3DX_FILTER_NONE,
0) != D3D_OK)
{
goto fail;
}

if (surface != NULL)
{
surface->Release();
surface = NULL;
}
free(data);
return ZUN_SUCCESS;

fail:
if (surface != NULL)
{
surface->Release();
surface = NULL;
}
free(data);
return ZUN_ERROR;
}

void AnmManager::ReleaseSurface(i32 surfaceIdx)
{
if (this->surfaces[surfaceIdx] != NULL)
{
this->surfaces[surfaceIdx]->Release();
this->surfaces[surfaceIdx] = NULL;
}
if (this->surfacesBis[surfaceIdx] != NULL)
{
this->surfacesBis[surfaceIdx]->Release();
this->surfacesBis[surfaceIdx] = NULL;
}
return;
}

void AnmManager::CopySurfaceToBackBuffer(i32 surfaceIdx, i32 left, i32 top, i32 x, i32 y)
{
if (this->surfacesBis[surfaceIdx] == NULL)
{
return;
}

IDirect3DSurface8 *destSurface;
if (g_Supervisor.d3dDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &destSurface) != D3D_OK)
{
return;
}
if (this->surfaces[surfaceIdx] == NULL)
{
if (g_Supervisor.d3dDevice->CreateRenderTarget(
this->surfaceSourceInfo[surfaceIdx].Width, this->surfaceSourceInfo[surfaceIdx].Height,
g_Supervisor.presentParameters.BackBufferFormat, D3DMULTISAMPLE_NONE, TRUE,
&this->surfaces[surfaceIdx]) != D3D_OK)
{
if (g_Supervisor.d3dDevice->CreateImageSurface(
this->surfaceSourceInfo[surfaceIdx].Width, this->surfaceSourceInfo[surfaceIdx].Height,
g_Supervisor.presentParameters.BackBufferFormat, &this->surfaces[surfaceIdx]) != D3D_OK)
{
destSurface->Release();
return;
}
}
if (D3DXLoadSurfaceFromSurface(this->surfaces[surfaceIdx], NULL, NULL, this->surfacesBis[surfaceIdx], NULL,
NULL, D3DX_FILTER_NONE, 0) != D3D_OK)
{
destSurface->Release();
return;
}
}

RECT sourceRect;
POINT destPoint;
sourceRect.left = left;
sourceRect.top = top;
sourceRect.right = this->surfaceSourceInfo[surfaceIdx].Width;
sourceRect.bottom = this->surfaceSourceInfo[surfaceIdx].Height;
destPoint.x = x;
destPoint.y = y;
g_Supervisor.d3dDevice->CopyRects(this->surfaces[surfaceIdx], &sourceRect, 1, destSurface, &destPoint);
destSurface->Release();
}

ZunResult AnmManager::LoadAnm(i32 anmIdx, char *path, i32 spriteIdxOffset)
{
this->ReleaseAnm(anmIdx);
this->anmFiles[anmIdx] = (AnmRawEntry *)FileSystem::OpenPath(path, 0);
AnmRawEntry *anmData = this->anmFiles[anmIdx];
if (anmData == NULL)
{
GameErrorContextFatal(&g_GameErrorContext, TH_ERR_ANMMANAGER_SPRITE_CORRUPTED, path);
return ZUN_ERROR;
}

anmData->textureIdx = anmIdx;
char *anmName = (char *)((u8 *)anmData + anmData->nameOffset);
if (*anmName == '@')
{
this->CreateEmptyTexture(anmData->textureIdx, anmData->width, anmData->height, anmData->format);
}
else
{
if (this->LoadTexture(anmData->textureIdx, anmName, anmData->format, anmData->colorKey) != 0)
{
GameErrorContextFatal(&g_GameErrorContext, TH_ERR_ANMMANAGER_TEXTURE_CORRUPTED, anmName);
return ZUN_ERROR;
}
}
if (anmData->mipmapNameOffset != 0)
{
anmName = (char *)((u8 *)anmData + anmData->mipmapNameOffset);
if (this->LoadTextureMipmap(anmData->textureIdx, anmName, anmData->format, anmData->colorKey) != 0)
{
GameErrorContextFatal(&g_GameErrorContext, TH_ERR_ANMMANAGER_TEXTURE_CORRUPTED, anmName);
return ZUN_ERROR;
}
}
anmData->spriteIdxOffset = spriteIdxOffset;
u32 *curSpriteOffset = (u32 *)anmData->data;
for (i32 i = 0; i < this->anmFiles[anmIdx]->numSprites; i++, curSpriteOffset++)
{
AnmRawSprite *rawSprite = (AnmRawSprite *)((u8 *)anmData + *curSpriteOffset);
AnmLoadedSprite loadedSprite;
loadedSprite.sourceFileIndex = this->anmFiles[anmIdx]->textureIdx;
loadedSprite.startPixelInclusive.x = rawSprite->offset.x;
loadedSprite.startPixelInclusive.y = rawSprite->offset.y;
loadedSprite.endPixelInclusive.x = rawSprite->offset.x + rawSprite->size.x;
loadedSprite.endPixelInclusive.y = rawSprite->offset.y + rawSprite->size.y;
loadedSprite.textureWidth = (float)anmData->width;
loadedSprite.textureHeight = (float)anmData->height;
this->LoadSprite(rawSprite->id + spriteIdxOffset, &loadedSprite);
}
for (i = 0; i < anmData->numScripts; i++, curSpriteOffset += 2)
{
this->scripts[curSpriteOffset[0] + spriteIdxOffset] = (AnmRawInstr *)((u8 *)anmData + curSpriteOffset[1]);
this->spriteIndices[curSpriteOffset[0] + spriteIdxOffset] = spriteIdxOffset;
}
this->anmFilesSpriteIndexOffsets[anmIdx] = spriteIdxOffset;
return ZUN_SUCCESS;
}

void AnmManager::ReleaseAnm(i32 anmIdx)
{
// TODO: stub
}

ZunResult AnmManager::CreateEmptyTexture(u32 textureIdx, u32 width, u32 height, u32 textureFormat)
{
// TODO: stub
return ZUN_ERROR;
}
ZunResult AnmManager::LoadTexture(u32 textureIdx, char *textureName, u32 textureFormat, D3DCOLOR colorKey)
{
// TODO: stub
return ZUN_ERROR;
}
ZunResult AnmManager::LoadTextureMipmap(u32 textureIdx, char *textureName, u32 textureFormat, D3DCOLOR colorKey)
{
// TODO: stub
return ZUN_ERROR;
}
ZunResult AnmManager::LoadSprite(u32 spriteIdx, AnmLoadedSprite *sprite)
{
// TODO: stub
return ZUN_ERROR;
}

ZunResult AnmManager::SetActiveSprite(AnmVm *vm, u32 spriteIdx)
{
// TODO: stub
return ZUN_ERROR;
}

DIFFABLE_STATIC(AnmManager *, g_AnmManager)
Loading

0 comments on commit f5d3495

Please sign in to comment.