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

Add support for HD cams. #1344

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8485d30
Added type variable to Renderer + Added hd cam support for opengl.
mlgthatsme Aug 24, 2021
e4b25af
Merge remote-tracking branch 'origin/master'
mlgthatsme Aug 24, 2021
1d98b56
fix compile poop
mlgthatsme Aug 24, 2021
763bf8c
Change LoadCustomCAM to LoadExternalCam - Add warning logs
mlgthatsme Sep 1, 2021
3e68c03
imgui demo code included in cmake
mlgthatsme Dec 2, 2021
83a4a57
finally fixed issue where certain sprites rendered incorrectly.
mlgthatsme Dec 2, 2021
6c8e7d4
removed redundant rendererType variable
mlgthatsme Dec 2, 2021
a046cb0
fixed issue where background wasn't loading properly.
mlgthatsme Dec 3, 2021
10e40d7
add checks for opengl calls + gpu info window
mlgthatsme Dec 4, 2021
3a1c94a
Call end frame.
mlgthatsme Dec 9, 2021
24eb07f
Merge remote-tracking branch 'origin/master' into opengl
mlgthatsme Dec 29, 2021
7ed4239
Merge remote-tracking branch 'origin/master' into opengl
mlgthatsme Jan 8, 2022
5444a82
Merge remote-tracking branch 'origin/master' into opengl
mlgthatsme Jan 8, 2022
30f4f4c
add imgui stdlib for std::string helper functions
mlgthatsme Feb 20, 2022
80ee9f3
asset tool + extra masher funcs
mlgthatsme Feb 20, 2022
b5778ad
add variable to know if game is ae or ae
mlgthatsme Feb 20, 2022
1c10b53
add present to renderer functions + hd asset loading wip
mlgthatsme Feb 20, 2022
ab43d65
Merge branch 'AliveTeam:master' into opengl
mlgthatsme Feb 20, 2022
042a375
fix some warnings
mlgthatsme Feb 20, 2022
143cf86
check if folder name is valid for loading external assets. skip on fail
mlgthatsme Feb 20, 2022
71146ae
Change how we apply hd textures, use global table instead
mlgthatsme Feb 20, 2022
62fa3a0
Make slig render in shadows properly
mlgthatsme Feb 20, 2022
6609f97
make it so emissive textures only render if object is dark
mlgthatsme Feb 20, 2022
e3062e3
fix signed char causing overflow issues with rgb color
mlgthatsme Feb 23, 2022
37d1a6f
fix incorrect resource files for abe falling and die
mlgthatsme Feb 23, 2022
f9ea48c
new and improved
mlgthatsme Feb 23, 2022
9416fb0
add support for flipped textures and flipped emissive textures
mlgthatsme Feb 23, 2022
64bf2e9
fix a bunch of anims not exporting due to wrong anim info
mouzedrift Oct 18, 2022
cfc605f
AO hd cam support + meta json error handling
mouzedrift Oct 21, 2022
6523a83
fix wrong paramite animation names
mouzedrift Apr 21, 2023
8c0ab04
enable RENDERER_OPENGL by default
mouzedrift Apr 21, 2023
89ab3b9
fix warnings
mouzedrift Apr 22, 2023
fc127a4
normalize flying slig anim id names
mouzedrift Apr 30, 2023
8e63510
make loading hd sprites a bit faster
mouzedrift Apr 19, 2024
72eb641
don't try to play movies
mouzedrift May 24, 2024
b1eddbf
don't load broken fg1 in AO
mouzedrift May 24, 2024
b34d8b0
show progress while loading external animations
mouzedrift May 24, 2024
7fea3cb
add ability to toggle the debug window and external assets using F1 a…
mouzedrift May 25, 2024
e6593da
add original data to meta.json files
mouzedrift Jun 19, 2024
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
7 changes: 7 additions & 0 deletions Source/AliveLibAE/Renderer/DirectX9Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void DirectX9Renderer::Destroy()

bool DirectX9Renderer::Create(TWindowHandleType window)
{
rendererType = Renderers::DirectX9;
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't used anywhere

Copy link
Member Author

Choose a reason for hiding this comment

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

how are we supposed to tell what renderer the user would be using? how would you approach that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Use polymorphic calls to abstract it out - e.g Create is a virtual call so DirectX9Renderer::Create know its the directx impl. If something outside of the object using the base type needs to know this then its probably leaking implementation details.

But its not even used currently so its dead code anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

alright. done.


// Find the directx9 driver
const s32 numDrivers = SDL_GetNumRenderDrivers();
if (numDrivers < 0)
Expand Down Expand Up @@ -180,4 +182,9 @@ void DirectX9Renderer::Upload(BitDepth /*bitDepth*/, const PSX_RECT& /*rect*/, c
{
}

void DirectX9Renderer::LoadExternalCam(const char* /*path*/, const unsigned char* /*key*/, int /*keyLength*/)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

should prob log it isn't implemented with LOG_WARNING

LOG_WARNING("LoadExternalCam not implemented for DirectX9 - external cam not loaded.");
}

#endif
2 changes: 2 additions & 0 deletions Source/AliveLibAE/Renderer/DirectX9Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class DirectX9Renderer final : public IRenderer

void Upload(BitDepth bitDepth, const PSX_RECT& rect, const u8* pPixels) override;

void LoadExternalCam(const char* path, const unsigned char* key, int keyLength) override;

private:
SDL_Renderer* mRenderer = nullptr;
IDirect3DDevice9* mDevice = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Source/AliveLibAE/Renderer/IRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "OpenGLRenderer.hpp"
#include "DirectX9Renderer.hpp"

static IRenderer* gRenderer = nullptr;
IRenderer* gRenderer = nullptr;

IRenderer* IRenderer::GetRenderer()
{
Expand Down
9 changes: 8 additions & 1 deletion Source/AliveLibAE/Renderer/IRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class IRenderer
public:
enum class Renderers
{
None = 0,
Software,
DirectX9,
OpenGL,
Expand All @@ -36,6 +37,8 @@ class IRenderer
};

public:
Renderers rendererType = Renderers::None;

virtual ~IRenderer()
{ }
virtual void Destroy() = 0;
Expand All @@ -59,6 +62,8 @@ class IRenderer

virtual void Upload(BitDepth bitDepth, const PSX_RECT& rect, const u8* pPixels) = 0;

virtual void LoadExternalCam(const char* path, const unsigned char* key, int keyLength) = 0;

// FG1/zaplines/blood/hintfly
virtual void Draw(Prim_Sprt& sprt) = 0;
virtual void Draw(Prim_GasEffect& gasEffect) = 0;
Expand Down Expand Up @@ -89,4 +94,6 @@ class IRenderer

// Fleech (tounge), DeathGas, ColourfulMeter
virtual void Draw(Poly_G4& poly) = 0;
};
};

extern IRenderer* gRenderer;
55 changes: 26 additions & 29 deletions Source/AliveLibAE/Renderer/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ void OpenGLRenderer::Destroy()

bool OpenGLRenderer::Create(TWindowHandleType window)
{
rendererType = Renderers::OpenGL;

mWindow = window;
mWireframe = false;

Expand Down Expand Up @@ -1544,42 +1546,39 @@ void OpenGLRenderer::Upload(BitDepth bitDepth, const PSX_RECT& rect, const u8* p
}
}

void HackSetBackground(const char_type* path)
void OpenGLRenderer::LoadExternalCam(const char* path, const unsigned char* key, int keyLength)
{
//return;

const char_type* camSearchs[] = {
"hd/%s.PNG",
"hd/%s.CAM.PNG",
"hd/%s.CAM.cam.PNG"};
std::vector<BYTE> fileData;

FILE* fh = NULL;
// Try to keep all paths and filenames lowercase for our linux friends.
std::ifstream file("hd/" + std::string(path).substr(0, 8) + ".cam2", std::ios::binary);

for (s32 i = 0; i < 3; i++)
if (file.is_open())
{
char_type newPath[100];
char_type camHack[9] = {};
memcpy(camHack, path, 8);
sprintf(newPath, camSearchs[i], camHack);
fh = fopen(newPath, "rb");

if (fh != NULL)
{
break;
}
fileData = std::vector<BYTE>((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
}

if (fh == NULL)
if (fileData.size() == 0)
{
/*glDeleteTextures(1, &mBackgroundTexture);
mBackgroundTexture = 0;*/
glDeleteTextures(1, &mBackgroundTexture);
mBackgroundTexture = 0;
return;
}

s32 x = 0, y = 0;
s32 comp = 0;
const u8* data = stbi_load_from_file(fh, &x, &y, &comp, 4);
BYTE* fPtr = fileData.data();

// XOR the custom cam file with the data from the original game.
// You wouldn't steal an Abe? https://www.youtube.com/watch?v=HmZm8vNHBSU
for (unsigned int i = 0; i < fileData.size(); i++)
{
fPtr[i] ^= key[i % keyLength];
}

int x = 0, y = 0, comp = 0;
const unsigned char* data = stbi_load_from_memory(fileData.data(), static_cast<int>(fileData.size()), &x, &y, &comp, 4);

// Check if we've created a texture handle already, if not, do so.
if (mBackgroundTexture == 0)
{
glGenTextures(1, &mBackgroundTexture);
Expand All @@ -1594,7 +1593,5 @@ void HackSetBackground(const char_type* path)

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

stbi_image_free((void*) data);

fclose(fh);
}
stbi_image_free((void*)data);
}
6 changes: 3 additions & 3 deletions Source/AliveLibAE/Renderer/OpenGLRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class OpenGLRenderer final : public IRenderer

void Upload(BitDepth bitDepth, const PSX_RECT& rect, const u8* pPixels) override;

void LoadExternalCam(const char* path, const unsigned char* key, int keyLength) override;

private:
SDL_Window* mWindow = nullptr;
SDL_GLContext mContext = nullptr;
Expand Down Expand Up @@ -110,6 +112,4 @@ class OpenGLRenderer final : public IRenderer
void DrawLines(const VertexData* pVertData, s32 vertSize, const GLuint* pIndData, s32 indSize);

void RenderBackground();
};

void HackSetBackground(const char_type* path);
};
6 changes: 6 additions & 0 deletions Source/AliveLibAE/Renderer/SoftwareRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void SoftwareRenderer::Destroy()

bool SoftwareRenderer::Create(TWindowHandleType window)
{
rendererType = Renderers::Software;
mRenderer = SDL_CreateRenderer(window, -1, 0);
return mRenderer != nullptr;
}
Expand Down Expand Up @@ -231,3 +232,8 @@ void SoftwareRenderer::Upload(BitDepth bitDepth, const PSX_RECT& rect, const u8*
break;
}
}

void SoftwareRenderer::LoadExternalCam(const char* /*path*/, const unsigned char* /*key*/, int /*keyLength*/)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

should prob log it isn't implemented with LOG_WARNING

LOG_WARNING("LoadExternalCam not implemented for Software Renderer - external cam not loaded.");
}
2 changes: 2 additions & 0 deletions Source/AliveLibAE/Renderer/SoftwareRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class SoftwareRenderer : public IRenderer

void Upload(BitDepth bitDepth, const PSX_RECT& rect, const u8* pPixels) override;

void LoadExternalCam(const char* path, const unsigned char* key, int keyLength) override;

private:
bool mFrameStarted = false;

Expand Down
13 changes: 13 additions & 0 deletions Source/AliveLibAE/ScreenManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "VRam.hpp"
#include "Psx.hpp"
#include "Renderer/IRenderer.hpp"
#include "Map.hpp"
#include "PathData.hpp"
#include "Renderer/IRenderer.hpp"
#include "Renderer/OpenGLRenderer.hpp"

ALIVE_VAR(1, 0x5BB5F4, ScreenManager*, pScreenManager_5BB5F4, nullptr);
ALIVE_ARY(1, 0x5b86c8, SprtTPage, 300, sSpriteTPageBuffer_5B86C8, {});
Expand Down Expand Up @@ -463,6 +467,15 @@ void ScreenManager::DecompressCameraToVRam_40EF60(u16** ppBits)
UnsetDirtyBits_40EDE0(1);
UnsetDirtyBits_40EDE0(2);
UnsetDirtyBits_40EDE0(3);

char camName[32] = {};
Path_Format_CameraName_460FB0(
camName,
gMap_5C3030.field_0_current_level,
gMap_5C3030.field_2_current_path,
gMap_5C3030.field_4_current_camera);

gRenderer->LoadExternalCam(camName, reinterpret_cast<const unsigned char*>(*ppBits), 512);
}

ScreenManager* ScreenManager::ctor_40E3E0(u8** ppBits, FP_Point* pCameraOffset)
Expand Down