Skip to content

Commit

Permalink
latest code
Browse files Browse the repository at this point in the history
  • Loading branch information
EqUiNoX-Labs committed Feb 3, 2025
1 parent 15f10bd commit 9cddcdf
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 9 deletions.
9 changes: 9 additions & 0 deletions NexgenRedux-OG/NexgenRedux-OG.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@
<File
RelativePath="..\NexgenRedux-Shared\EntityEngine\PerspectiveCamera.h">
</File>
<File
RelativePath="..\NexgenRedux-Shared\EntityEngine\PreLoader.cpp">
</File>
<File
RelativePath="..\NexgenRedux-Shared\EntityEngine\PreLoader.h">
</File>
<File
RelativePath="..\NexgenRedux-Shared\EntityEngine\SceneManager.cpp">
</File>
Expand Down Expand Up @@ -524,6 +530,9 @@
<File
RelativePath="..\Libraries\Gensys\NetworkManager.h">
</File>
<File
RelativePath="..\Libraries\Gensys\PointerVector.h">
</File>
<File
RelativePath="..\Libraries\Gensys\SocketUtility.cpp">
</File>
Expand Down
6 changes: 6 additions & 0 deletions NexgenRedux-Shared/AngelScriptRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "EntityEngine/Fog.h"
#include "EntityEngine/Lighting.h"
#include "EntityEngine/Sprite.h"
#include "EntityEngine/PreLoader.h"
#include "EntityEngine/Text.h"

#include <Gensys/DebugUtility.h>
Expand Down Expand Up @@ -967,6 +968,11 @@ bool AngelScriptRunner::Init()
result = m_engine->RegisterGlobalFunction("void SceneManager::SetCurrentScene(uint)", asFUNCTION(SceneManager::SetCurrentScene), asCALL_CDECL); if (result < 0) { return false; }
result = m_engine->RegisterGlobalFunction("bool SceneManager::AssignNode(Node@, uint)", asFUNCTION(SceneManager::AssignNode), asCALL_CDECL); if (result < 0) { return false; }

result = m_engine->SetDefaultNamespace("PreLoader"); if (result < 0) { return false; }
result = m_engine->RegisterGlobalFunction("void LoadTexture(string)", asFUNCTION(PreLoader::LoadTexture), asCALL_CDECL); if (result < 0) { return false; }
result = m_engine->RegisterGlobalFunction("void UnLoadTexture(string)", asFUNCTION(PreLoader::UnLoadTexture), asCALL_CDECL); if (result < 0) { return false; }
result = m_engine->RegisterGlobalFunction("void WaitTexturesLoaded()", asFUNCTION(PreLoader::WaitTexturesLoaded), asCALL_CDECL); if (result < 0) { return false; }

result = m_engine->SetDefaultNamespace("FontManager"); if (result < 0) { return false; }
result = m_engine->RegisterGlobalFunction("bool FontManager::LoadFont(string)", asFUNCTION(FontManager::LoadFont), asCALL_CDECL); if (result < 0) { return false; }

Expand Down
97 changes: 97 additions & 0 deletions NexgenRedux-Shared/EntityEngine/PreLoader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "PreLoader.h"
#include "RenderStateManager.h"
#include "TextureManager.h"

#include <Gensys/DebugUtility.h>
#include <Gensys/StringUtility.h>
#include <Gensys/TimeUtility.h>
#include <stdexcept>
#include <algorithm>
#include <string>
#include <vector>

using namespace Gensys;
using namespace NexgenRedux;

namespace
{
std::vector<std::string> m_textureKeys;
}

void PreLoader::Close(void)
{
RenderStateManager* renderStateManager = RenderStateManager::GetInstance();

for (size_t i = 0; i < m_textureKeys.size(); ++i)
{
const std::string value = m_textureKeys[i];

uint32_t textureID = 0;
bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(value), textureID);
if (textureExists == true)
{
renderStateManager->DeleteTextureReference(textureID);
}
}
}

void PreLoader::LoadTexture(const std::string value)
{
// Only load if we dont a ref to key ourselves
if (std::find(m_textureKeys.begin(), m_textureKeys.end(), value) != m_textureKeys.end())
{
return;
}

RenderStateManager* renderStateManager = RenderStateManager::GetInstance();

uint32_t textureID = 0;

bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(value), textureID);
renderStateManager->CreateTextureReference(StringUtility::ToWideString(value), textureID);
if (textureExists == false)
{
TextureManager::Request(StringUtility::ToWideString(value), textureID);
}
}

void PreLoader::UnLoadTexture(const std::string value)
{
// Only unload if we have a ref to key ourselves
if (std::find(m_textureKeys.begin(), m_textureKeys.end(), value) == m_textureKeys.end())
{
return;
}

RenderStateManager* renderStateManager = RenderStateManager::GetInstance();

uint32_t textureID = 0;

bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(value), textureID);
if (textureExists == true)
{
renderStateManager->DeleteTextureReference(textureID);
}
}

void PreLoader::WaitTexturesLoaded()
{
// This should not be called until render engine / window created

RenderStateManager* renderStateManager = RenderStateManager::GetInstance();

for (size_t i = 0; i < m_textureKeys.size(); ++i)
{
const std::string value = m_textureKeys[i];

uint32_t textureID = 0;
bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(value), textureID);
if (textureExists == true)
{
while (renderStateManager->IsTextureLoaded(textureID) == false)
{
TimeUtility::SleepMilliseconds(100);
}
}
}
}
15 changes: 15 additions & 0 deletions NexgenRedux-Shared/EntityEngine/PreLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <string>

namespace NexgenRedux
{
class PreLoader
{
public:
static void Close(void);
static void LoadTexture(const std::string value);
static void UnLoadTexture(const std::string value);
static void WaitTexturesLoaded();
};
}
2 changes: 1 addition & 1 deletion NexgenRedux-Shared/EntityEngine/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Sprite::Update(float dt)
{
renderStateManager->DeleteTextureReference(m_textureID);
}
bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(m_texturePath));
bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(m_texturePath), m_textureID);
renderStateManager->CreateTextureReference(StringUtility::ToWideString(m_texturePath), m_textureID);
if (textureExists == false)
{
Expand Down
2 changes: 1 addition & 1 deletion NexgenRedux-Shared/IRenderingHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace NexgenRedux
virtual void SetViewport(const MathUtility::RectI rect) = 0;
virtual void SetScissor(const ScissorOperation& operation, const MathUtility::RectI& rect) = 0;
virtual bool LoadTexture(const std::wstring& path, uint32_t& textureID) = 0;
virtual bool TextureExists(const std::wstring& key) = 0;
virtual bool TextureExists(const std::wstring& key, uint32_t& textureID) = 0;
virtual bool CreateTextureReference(const std::wstring& key, uint32_t& textureID) = 0;
virtual bool DeleteTextureReference(const uint32_t& textureID) = 0;
virtual bool IsTextureLoaded(const uint32_t& textureID) = 0;
Expand Down
9 changes: 9 additions & 0 deletions NexgenRedux-Shared/Media/Shooter/main.as
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,13 @@ void UpdateBackground(double dt)
void Init()
{
FontManager::LoadFont("skin:asset\\fonts\\freesans.sfn");
//PreLoader::LoadTexture("asset:images\\TR_Banner_Background.jpg");
//PreLoader::LoadTexture("asset:images\\game\\playerbullet.png");
//PreLoader::LoadTexture("asset:images\\game\\boss.png");
//PreLoader::LoadTexture("asset:images\\game\\PineappleShip.png");
//PreLoader::LoadTexture("asset:images\\backgrounds\\Nebula Aqua-Pink.png");
//PreLoader::LoadTexture("asset:images\\backgrounds\\Stars-Big_1_2_PC.png");
//PreLoader::LoadTexture("asset:images\\backgrounds\\Stars-Big_1_1_PC.png");

uint sceneID = SceneManager::CreateScene(true);
SceneManager::SetCurrentScene(sceneID);
Expand Down Expand Up @@ -706,6 +713,8 @@ void Init()

// Create window example
WindowCreateWithSize(640, 480, "Nexgen Redux - Shooter Demo");

PreLoader::WaitTexturesLoaded();


SetWindowIconifyCallback(OnWindowIconify);
Expand Down
3 changes: 2 additions & 1 deletion NexgenRedux-Shared/OpenGLRenderingHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,14 +874,15 @@ bool OpenGLRenderingHelper::LoadTexture(const std::wstring& path, uint32_t& text
return false;
}

bool OpenGLRenderingHelper::TextureExists(const std::wstring& key)
bool OpenGLRenderingHelper::TextureExists(const std::wstring& key, uint32_t& textureID)
{
for (std::map<uint32_t, TextureContainer>::iterator it = m_textureContainerMap.begin(); it != m_textureContainerMap.end(); ++it)
{
if (it->second.key != key)
{
continue;
}
textureID = it->first;
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion NexgenRedux-Shared/OpenGLRenderingHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace NexgenRedux
void SetScissor(const ScissorOperation& operation, const MathUtility::RectI& rect) override;

bool LoadTexture(const std::wstring& path, uint32_t& textureID) override;
bool TextureExists(const std::wstring& key) override;
bool TextureExists(const std::wstring& key, uint32_t& textureID) override;
bool CreateTextureReference(const std::wstring& key, uint32_t& textureID) override;
bool DeleteTextureReference(const uint32_t& textureID) override;
bool IsTextureLoaded(const uint32_t& textureID);
Expand Down
4 changes: 2 additions & 2 deletions NexgenRedux-Shared/RenderStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ bool RenderStateManager::LoadTexture(const std::wstring& path, uint32_t& texture
return m_renderingHelper->LoadTexture(path, textureID);
}

bool RenderStateManager::TextureExists(const std::wstring& key)
bool RenderStateManager::TextureExists(const std::wstring& key, uint32_t& textureID)
{
return m_renderingHelper->TextureExists(key);
return m_renderingHelper->TextureExists(key, textureID);
}

bool RenderStateManager::CreateTextureReference(const std::wstring& key, uint32_t& textureID)
Expand Down
2 changes: 1 addition & 1 deletion NexgenRedux-Shared/RenderStateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace NexgenRedux
RenderState* GetRenderState(void);
bool CanBatch(void);
bool LoadTexture(const std::wstring& path, uint32_t& textureID);
bool TextureExists(const std::wstring& key);
bool TextureExists(const std::wstring& key, uint32_t& textureID);
bool CreateTextureReference(const std::wstring& key, uint32_t& textureID);
bool DeleteTextureReference(const uint32_t& textureID);
bool IsTextureLoaded(const uint32_t& textureID);
Expand Down
3 changes: 2 additions & 1 deletion NexgenRedux-Shared/XboxOGRenderingHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,14 +1058,15 @@ bool XboxOGRenderingHelper::LoadTexture(const std::wstring& path, uint32_t& text
return true;
}

bool XboxOGRenderingHelper::TextureExists(const std::wstring& key)
bool XboxOGRenderingHelper::TextureExists(const std::wstring& key, uint32_t& textureID)
{
for (std::map<uint32_t, TextureContainer>::iterator it = m_textureContainerMap.begin(); it != m_textureContainerMap.end(); ++it)
{
if (it->second.key != key)
{
continue;
}
textureID = it->first;
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion NexgenRedux-Shared/XboxOGRenderingHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace NexgenRedux
void SetScissor(const ScissorOperation& operation, const MathUtility::RectI& rect);

bool LoadTexture(const std::wstring& path, uint32_t& textureID);
bool TextureExists(const std::wstring& key);
bool TextureExists(const std::wstring& key, uint32_t& textureID);
bool CreateTextureReference(const std::wstring& key, uint32_t& textureID);
bool DeleteTextureReference(const uint32_t& textureID);
bool IsTextureLoaded(const uint32_t& textureID);
Expand Down

0 comments on commit 9cddcdf

Please sign in to comment.