-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from roblabla/SupervisorChain
Implement Supervisor chain
- Loading branch information
Showing
22 changed files
with
1,155 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.