1
0
forked from 0ad/0ad

less global variables: make most uses of g_VFS explicit (required for another app that has two VFSes), g_yres is no longer required by cursor module

This was SVN commit r7686.
This commit is contained in:
janwas 2010-07-04 10:15:53 +00:00
parent d764473844
commit d2cf6ceb88
48 changed files with 199 additions and 154 deletions

View File

@ -102,7 +102,7 @@ public:
set_logger(ColladaLog);
CVFSFile skeletonFile;
if (skeletonFile.Load(L"art/skeletons/skeletons.xml") != PSRETURN_OK)
if (skeletonFile.Load(g_VFS, L"art/skeletons/skeletons.xml") != PSRETURN_OK)
{
LOG(CLogger::Error, LOG_CATEGORY, L"Failed to read skeleton definitions");
dll.Unload();
@ -127,7 +127,7 @@ public:
CStr daeData;
{
CVFSFile daeFile;
if (daeFile.Load(daeFilename) != PSRETURN_OK)
if (daeFile.Load(g_VFS, daeFilename) != PSRETURN_OK)
return false;
daeData = daeFile.GetAsString();
}

View File

@ -311,7 +311,7 @@ void CXMLReader::Init(const VfsPath& xml_filename)
// must only assign once, so do it here
node_idx = entity_idx = nonentity_idx = 0;
if (xmb_file.Load(xml_filename) != PSRETURN_OK)
if (xmb_file.Load(g_VFS, xml_filename) != PSRETURN_OK)
throw PSERROR_File_ReadFailed();
// define the elements and attributes that are frequently used in the XML file,
@ -374,7 +374,7 @@ void CXMLReader::ReadPlayers()
std::map<int, SColor3ub> playerDefaultColours;
CXeromyces playerDefaultFile;
if (playerDefaultFile.Load(L"simulation/data/players.xml") != PSRETURN_OK)
if (playerDefaultFile.Load(g_VFS, L"simulation/data/players.xml") != PSRETURN_OK)
throw PSERROR_File_ReadFailed();
#define AT(x) int at_##x = playerDefaultFile.GetAttributeID(#x)

View File

@ -379,7 +379,7 @@ void CMapWriter::WriteXML(const VfsPath& filename,
}
}
}
if (! XML_StoreVFS(filename))
if (! XML_StoreVFS(g_VFS, filename))
debug_assert(0); // failed to write map XML file
}

View File

@ -17,6 +17,7 @@
#include "precompiled.h"
#include "lib/ogl.h"
#include "ps/Filesystem.h"
#include "ps/XML/Xeromyces.h"
#include "MaterialManager.h"
@ -196,7 +197,7 @@ CMaterial& CMaterialManager::LoadMaterial(const VfsPath& pathname)
}
CXeromyces xeroFile;
if(xeroFile.Load(pathname) != PSRETURN_OK)
if(xeroFile.Load(g_VFS, pathname) != PSRETURN_OK)
return NullMaterial;
#define EL(x) int el_##x = xeroFile.GetElementID(#x)

View File

@ -24,6 +24,7 @@
#include "ObjectManager.h"
#include "ps/XML/Xeromyces.h"
#include "ps/Filesystem.h"
#include "ps/CLogger.h"
#include "lib/timer.h"
#include "lib/rand.h"
@ -42,7 +43,7 @@ CObjectBase::CObjectBase(CObjectManager& objectManager)
bool CObjectBase::Load(const VfsPath& pathname)
{
CXeromyces XeroFile;
if (XeroFile.Load(pathname) != PSRETURN_OK)
if (XeroFile.Load(g_VFS, pathname) != PSRETURN_OK)
return false;
// Define all the elements used in the XML file

View File

@ -22,9 +22,9 @@
#include "precompiled.h"
#include "ParticleEmitter.h"
#include "ParticleEngine.h"
#include "ps/XML/Xeromyces.h"
#include "ps/Filesystem.h"
#include "ps/CLogger.h"
#include "ps/XML/Xeromyces.h"
#define LOG_CATEGORY L"particleSystem"
//forward declaration
@ -64,7 +64,7 @@ CEmitter::~CEmitter(void)
bool CEmitter::LoadXml(const VfsPath& pathname)
{
CXeromyces XeroFile;
if (XeroFile.Load(pathname) != PSRETURN_OK)
if (XeroFile.Load(g_VFS, pathname) != PSRETURN_OK)
// Fail
return false;

View File

@ -16,19 +16,21 @@
*/
#include "precompiled.h"
#include "TerrainProperties.h"
#include <vector>
#include <string>
#include "TerrainProperties.h"
#include "TextureManager.h"
#include "ps/Overlay.h"
#include "ps/Filesystem.h"
#include "ps/CLogger.h"
#include "ps/Parser.h"
#include "ps/XML/XeroXMB.h"
#include "ps/XML/Xeromyces.h"
#include "ps/CLogger.h"
#include "TextureManager.h"
#include "ps/Overlay.h"
CTerrainProperties::CTerrainProperties(CTerrainPropertiesPtr parent):
m_pParent(parent),
@ -43,7 +45,7 @@ CTerrainProperties::CTerrainProperties(CTerrainPropertiesPtr parent):
CTerrainPropertiesPtr CTerrainProperties::FromXML(const CTerrainPropertiesPtr& parent, const VfsPath& pathname)
{
CXeromyces XeroFile;
if (XeroFile.Load(pathname) != PSRETURN_OK)
if (XeroFile.Load(g_VFS, pathname) != PSRETURN_OK)
return CTerrainPropertiesPtr();
XMBElement root = XeroFile.GetRoot();

View File

@ -21,6 +21,7 @@
#include <map>
#include "lib/res/handle.h"
#include "lib/file/vfs/vfs_path.h"
#include "ps/CStr.h"
#include "TextureManager.h"

View File

@ -23,6 +23,7 @@
#include <boost/shared_ptr.hpp>
#include "lib/res/handle.h"
#include "lib/file/vfs/vfs_path.h"
#include "ps/CStr.h"
#include "ps/Singleton.h"

View File

@ -987,7 +987,7 @@ void CGUI::LoadXmlFile(const VfsPath& Filename, std::set<VfsPath>& Paths)
Paths.insert(Filename);
CXeromyces XeroFile;
if (XeroFile.Load(Filename) != PSRETURN_OK)
if (XeroFile.Load(g_VFS, Filename) != PSRETURN_OK)
// Fail silently
return;
@ -1300,7 +1300,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
{
Paths.insert(filename);
CVFSFile scriptfile;
if (scriptfile.Load(filename) != PSRETURN_OK)
if (scriptfile.Load(g_VFS, filename) != PSRETURN_OK)
{
LOGERROR(L"Error opening GUI script action file '%ls'", filename.c_str());
throw PSERROR_GUI_JSOpenFailed();

View File

@ -22,6 +22,7 @@
#include "CGUI.h"
#include "lib/timer.h"
#include "ps/Filesystem.h"
#include "ps/CLogger.h"
#include "ps/Profile.h"
#include "ps/XML/Xeromyces.h"
@ -136,7 +137,7 @@ void CGUIManager::LoadPage(SGUIPage& page)
page.inputs.insert(path);
CXeromyces xero;
if (xero.Load(path) != PSRETURN_OK)
if (xero.Load(g_VFS, path) != PSRETURN_OK)
// Fail silently (Xeromyces reported the error)
return;

View File

@ -24,6 +24,7 @@
#include "lib/res/h_mgr.h"
#include "lib/tex/tex.h"
#include "ps/Filesystem.h"
#include "ps/CLogger.h"
#define LOG_CATEGORY L"gui"
@ -417,7 +418,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName,
if (! cit->m_TextureName.empty())
{
Handle h = ogl_tex_load(cit->m_TextureName);
Handle h = ogl_tex_load(g_VFS, cit->m_TextureName);
if (h <= 0)
{
LOG(CLogger::Error, LOG_CATEGORY, L"Error reading texture '%ls': %ld", cit->m_TextureName.string().c_str(), (long)h);

View File

@ -34,9 +34,7 @@
#include "lib/ogl.h"
#include "lib/sysdep/cursor.h"
#include "ogl_tex.h"
#include "../h_mgr.h"
#include "lib/file/vfs/vfs.h"
extern PIVFS g_VFS;
#include "lib/res/h_mgr.h"
// On Windows, allow runtime choice between system cursors and OpenGL
// cursors (Windows = more responsive, OpenGL = more consistent with what
@ -48,7 +46,7 @@ extern PIVFS g_VFS;
#endif
static LibError load_sys_cursor(const VfsPath& pathname, int hx, int hy, sys_cursor* cursor)
static LibError load_sys_cursor(const PIVFS& vfs, const VfsPath& pathname, int hx, int hy, sys_cursor* cursor)
{
#if !ALLOW_SYS_CURSOR
UNUSED2(pathname);
@ -59,7 +57,7 @@ static LibError load_sys_cursor(const VfsPath& pathname, int hx, int hy, sys_cur
return ERR::FAIL;
#else
shared_ptr<u8> file; size_t fileSize;
RETURN_ERR(g_VFS->LoadFile(pathname, file, fileSize));
RETURN_ERR(vfs->LoadFile(pathname, file, fileSize));
ScopedTex t;
RETURN_ERR(tex_decode(file, fileSize, &t));
@ -87,9 +85,9 @@ class GLCursor
int hotspotx, hotspoty;
public:
LibError create(const VfsPath& pathname, int hotspotx_, int hotspoty_)
LibError create(const PIVFS& vfs, const VfsPath& pathname, int hotspotx_, int hotspoty_)
{
ht = ogl_tex_load(pathname);
ht = ogl_tex_load(vfs, pathname);
RETURN_ERR(ht);
size_t width, height;
@ -120,9 +118,6 @@ public:
glDisable(GL_DEPTH_TEST);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
// OpenGL's coordinate system is "upside-down"; correct for that.
y = g_yres - y;
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2i( x-hotspotx, y+hotspoty );
glTexCoord2i(1, 0); glVertex2i( x-hotspotx+w, y+hotspoty );
@ -189,7 +184,7 @@ static void Cursor_dtor(Cursor* c)
}
}
static LibError Cursor_reload(Cursor* c, const VfsPath& name, Handle)
static LibError Cursor_reload(Cursor* c, const PIVFS& vfs, const VfsPath& name, Handle)
{
const VfsPath path(L"art/textures/cursors");
const VfsPath pathname(path/name);
@ -200,7 +195,7 @@ static LibError Cursor_reload(Cursor* c, const VfsPath& name, Handle)
{
const VfsPath pathnameHotspot = fs::change_extension(pathname, L".txt");
shared_ptr<u8> buf; size_t size;
RETURN_ERR(g_VFS->LoadFile(pathnameHotspot, buf, size));
RETURN_ERR(vfs->LoadFile(pathnameHotspot, buf, size));
std::wstringstream s(std::wstring((const wchar_t*)buf.get(), size));
s >> hotspotx >> hotspoty;
}
@ -208,10 +203,10 @@ static LibError Cursor_reload(Cursor* c, const VfsPath& name, Handle)
const VfsPath pathnameImage = fs::change_extension(pathname, L".dds");
// try loading as system cursor (2d, hardware accelerated)
if(load_sys_cursor(pathnameImage, hotspotx, hotspoty, &c->system_cursor) == INFO::OK)
if(load_sys_cursor(vfs, pathnameImage, hotspotx, hotspoty, &c->system_cursor) == INFO::OK)
c->kind = CK_System;
// fall back to GLCursor (system cursor code is disabled or failed)
else if(c->gl_cursor.create(pathnameImage, hotspotx, hotspoty) == INFO::OK)
else if(c->gl_cursor.create(vfs, pathnameImage, hotspotx, hotspoty) == INFO::OK)
{
c->kind = CK_OpenGL;
// (we need to hide the system cursor when using a OpenGL cursor)
@ -282,9 +277,9 @@ static LibError Cursor_to_string(const Cursor* c, wchar_t* buf)
// in other words, we continually create/free the cursor resource in
// cursor_draw and trust h_mgr's caching to absorb it.
static Handle cursor_load(const VfsPath& name)
static Handle cursor_load(const PIVFS& vfs, const VfsPath& name)
{
return h_alloc(H_Cursor, name, 0);
return h_alloc(H_Cursor, vfs, name, 0);
}
static LibError cursor_free(Handle& h)
@ -293,7 +288,7 @@ static LibError cursor_free(Handle& h)
}
LibError cursor_draw(const wchar_t* name, int x, int y)
LibError cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y)
{
// hide the cursor
if(!name)
@ -302,7 +297,7 @@ LibError cursor_draw(const wchar_t* name, int x, int y)
return INFO::OK;
}
Handle hc = cursor_load(name);
Handle hc = cursor_load(vfs, name);
H_DEREF(hc, Cursor, c);
switch(c->kind)

View File

@ -27,18 +27,21 @@
#ifndef INCLUDED_GRAPHICS_CURSOR
#define INCLUDED_GRAPHICS_CURSOR
#include "lib/file/vfs/vfs.h"
/**
* draw the cursor on-screen.
*
* @param name base name of cursor or zero to hide the cursor.
* @param x,y coordinates [pixels] (origin is in the upper left)
* @param x,y coordinates [pixels] (origin at lower left)
* (the origin is convenient for drawing via OpenGL, but requires the
* mouse Y coordinate to be subtracted from the client area height.
* making the caller responsible for this avoids a dependency on
* the g_yres global variable.)
*
* uses a hardware mouse cursor where available, otherwise a
* portable OpenGL implementation.
**/
extern LibError cursor_draw(const wchar_t* name, int x, int y);
// internal use only:
extern int g_yres;
extern LibError cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y);
#endif // #ifndef INCLUDED_GRAPHICS_CURSOR

View File

@ -29,6 +29,7 @@
#include "lib/ogl.h"
#include "ps/Filesystem.h"
#include "ps/CStr.h"
#include "ps/CLogger.h"
#include "ps/XML/Xeromyces.h"
@ -36,7 +37,7 @@
#include "lib/timer.h"
#include "lib/res/h_mgr.h"
#include "lib/file/vfs/vfs.h"
extern PIVFS g_VFS;
extern PIVFS vfs;
#define LOG_CATEGORY L"shaders"
@ -111,7 +112,7 @@ TIMER_ADD_CLIENT(tc_linkProgram);
// have absolutely no effect on a program object that contains these shaders
// when the program object is already linked.
// So, how can we inform the "parent object" (i.e. the program object) of our change?
static LibError Ogl_Shader_reload(Ogl_Shader* shdr, const VfsPath& pathname, Handle UNUSED(h))
static LibError Ogl_Shader_reload(Ogl_Shader* shdr, const PIVFS& vfs, const VfsPath& pathname, Handle UNUSED(h))
{
LibError err = ERR::FAIL;
@ -119,7 +120,7 @@ static LibError Ogl_Shader_reload(Ogl_Shader* shdr, const VfsPath& pathname, Han
return INFO::OK;
shared_ptr<u8> file; size_t file_size;
RETURN_ERR(g_VFS->LoadFile(pathname, file, file_size));
RETURN_ERR(vfs->LoadFile(pathname, file, file_size));
ogl_WarnIfError();
@ -226,9 +227,9 @@ static LibError Ogl_Shader_to_string(const Ogl_Shader* shdr, wchar_t* buf)
// Create, load and compile a shader object of the given type
// (e.g. GL_VERTEX_SHADER_ARB). The given file will be used as
// source code for the shader.
Handle ogl_shader_load(const VfsPath& pathname, GLenum type)
Handle ogl_shader_load(const PIVFS& vfs, const VfsPath& pathname, GLenum type)
{
return h_alloc(H_Ogl_Shader, pathname, 0, type);
return h_alloc(H_Ogl_Shader, vfs, pathname, 0, type);
}
@ -307,7 +308,7 @@ static LibError do_load_shader(
WARN_RETURN(ERR::CORRUPTED);
}
Handle hshader = ogl_shader_load(CStrW(pathnameShader), shadertype);
Handle hshader = ogl_shader_load(g_VFS, CStrW(pathnameShader), shadertype);
RETURN_ERR(hshader);
ogl_shader_attach(p->id, hshader);
@ -323,7 +324,7 @@ static LibError do_load_shader(
// Reload the program object from the source file.
static LibError Ogl_Program_reload(Ogl_Program* p, const VfsPath& pathname, Handle h)
static LibError Ogl_Program_reload(Ogl_Program* p, const PIVFS& vfs, const VfsPath& pathname, Handle h)
{
if (p->id)
return INFO::OK;
@ -344,7 +345,7 @@ static LibError Ogl_Program_reload(Ogl_Program* p, const VfsPath& pathname, Hand
}
CXeromyces XeroFile;
if (XeroFile.Load(pathname) != PSRETURN_OK)
if (XeroFile.Load(vfs, pathname) != PSRETURN_OK)
WARN_RETURN(ERR::CORRUPTED); // more informative error message?
// Define all the elements and attributes used in the XML file
@ -449,9 +450,9 @@ static LibError Ogl_Program_to_string(const Ogl_Program* p, wchar_t* buf)
// Load a program object based on the given XML file description.
// Shader objects are loaded and attached automatically.
Handle ogl_program_load(const VfsPath& pathname)
Handle ogl_program_load(const PIVFS& vfs, const VfsPath& pathname)
{
return h_alloc(H_Ogl_Program, pathname, 0);
return h_alloc(H_Ogl_Program, vfs, pathname, 0);
}
// Free all resources associated with the given program handle.

View File

@ -28,6 +28,7 @@
#define INCLUDED_OGL_SHADER
#include "lib/res/handle.h"
#include "lib/file/vfs/vfs.h"
#include "lib/ogl.h"
@ -56,7 +57,7 @@ extensions are available, or all bets are off.
* @param pathname location of the file containing the shader's source code.
* @param type e.g. GL_VERTEX_SHADER_ARB.
**/
Handle ogl_shader_load(const VfsPath& pathname, GLenum type);
Handle ogl_shader_load(const PIVFS& vfs, const VfsPath& pathname, GLenum type);
/**
* Free all resources associated with the given handle
@ -81,7 +82,7 @@ Encapsulate program objects into handles.
*
* note: Shader objects are loaded and attached automatically.
**/
Handle ogl_program_load(const VfsPath& pathname);
Handle ogl_program_load(const PIVFS& vfs, const VfsPath& pathname);
/**
* Free all resources associated with the given program handle.

View File

@ -36,10 +36,8 @@
#include "lib/sysdep/gfx.h"
#include "lib/tex/tex.h"
#include "../h_mgr.h"
#include "lib/file/vfs/vfs.h"
#include "lib/res/h_mgr.h"
#include "lib/fnv_hash.h"
extern PIVFS g_VFS;
//----------------------------------------------------------------------------
@ -415,7 +413,7 @@ static void OglTex_dtor(OglTex* ot)
ot->flags &= ~OT_IS_UPLOADED;
}
static LibError OglTex_reload(OglTex* ot, const VfsPath& pathname, Handle h)
static LibError OglTex_reload(OglTex* ot, const PIVFS& vfs, const VfsPath& pathname, Handle h)
{
// we're reusing a freed but still in-memory OglTex object
if(ot->flags & OT_IS_UPLOADED)
@ -426,7 +424,7 @@ static LibError OglTex_reload(OglTex* ot, const VfsPath& pathname, Handle h)
if(!(ot->flags & OT_TEX_VALID))
{
shared_ptr<u8> file; size_t fileSize;
if(g_VFS->LoadFile(pathname, file, fileSize) >= 0)
if(vfs->LoadFile(pathname, file, fileSize) >= 0)
{
if(tex_decode(file, fileSize, &ot->t) >= 0)
ot->flags |= OT_TEX_VALID;
@ -497,10 +495,10 @@ static LibError OglTex_to_string(const OglTex* ot, wchar_t* buf)
// load and return a handle to the texture given in <pathname>.
// for a list of supported formats, see tex.h's tex_load.
Handle ogl_tex_load(const VfsPath& pathname, size_t flags)
Handle ogl_tex_load(const PIVFS& vfs, const VfsPath& pathname, size_t flags)
{
Tex* wrapped_tex = 0; // we're loading from file
return h_alloc(H_OglTex, pathname, flags, wrapped_tex);
return h_alloc(H_OglTex, vfs, pathname, flags, wrapped_tex);
}
@ -525,7 +523,7 @@ Handle ogl_tex_find(const VfsPath& pathname)
// note: because we cannot guarantee that callers will pass distinct
// "filenames", caching is disabled for the created object. this avoids
// mistakenly reusing previous objects that share the same comment.
Handle ogl_tex_wrap(Tex* t, const VfsPath& pathname, size_t flags)
Handle ogl_tex_wrap(Tex* t, const PIVFS& vfs, const VfsPath& pathname, size_t flags)
{
// this object may not be backed by a file ("may", because
// someone could do tex_load and then ogl_tex_wrap).
@ -535,7 +533,7 @@ Handle ogl_tex_wrap(Tex* t, const VfsPath& pathname, size_t flags)
// 'descriptive comment' instead of filename, but don't rely on that)
// also disable caching as explained above.
flags |= RES_DISALLOW_RELOAD|RES_NO_CACHE;
return h_alloc(H_OglTex, pathname, flags, t);
return h_alloc(H_OglTex, vfs, pathname, flags, t);
}

View File

@ -148,6 +148,7 @@ the next function to fail, but real apps should check and report errors.
#define INCLUDED_OGL_TEX
#include "lib/res/handle.h"
#include "lib/file/vfs/vfs.h"
#include "lib/ogl.h"
#include "lib/tex/tex.h"
@ -219,7 +220,7 @@ extern void ogl_tex_set_defaults(int q_flags, GLint filter);
* @return Handle to texture or negative LibError
* for a list of supported formats, see tex.h's tex_load.
*/
extern Handle ogl_tex_load(const VfsPath& pathname, size_t flags = 0);
extern Handle ogl_tex_load(const PIVFS& vfs, const VfsPath& pathname, size_t flags = 0);
/**
* Find and return an existing texture object, if it has already been
@ -248,7 +249,7 @@ extern Handle ogl_tex_find(const VfsPath& pathname);
* we need only add bookkeeping information and "wrap" it in
* a resource object (accessed via Handle), hence the name.
*/
extern Handle ogl_tex_wrap(Tex* t, const VfsPath& pathname, size_t flags = 0);
extern Handle ogl_tex_wrap(Tex* t, const PIVFS& vfs, const VfsPath& pathname, size_t flags = 0);
/**
* Release this texture reference. When the count reaches zero, all of

View File

@ -33,9 +33,7 @@
#include <map>
#include "ogl_tex.h"
#include "../h_mgr.h"
#include "lib/file/vfs/vfs.h"
extern PIVFS g_VFS;
#include "lib/res/h_mgr.h"
struct GlyphData
{
@ -74,7 +72,7 @@ static void UniFont_dtor(UniFont* f)
// basename is e.g. "console"; the files are "fonts/console.fnt" and "fonts/console.png"
// [10..70ms]
static LibError UniFont_reload(UniFont* f, const VfsPath& basename, Handle UNUSED(h))
static LibError UniFont_reload(UniFont* f, const PIVFS& vfs, const VfsPath& basename, Handle UNUSED(h))
{
// already loaded
if(f->ht > 0)
@ -87,7 +85,7 @@ static LibError UniFont_reload(UniFont* f, const VfsPath& basename, Handle UNUSE
// Read font definition file into a stringstream
shared_ptr<u8> buf; size_t size;
const VfsPath fntName(basename.string() + L".fnt");
RETURN_ERR(g_VFS->LoadFile(path/fntName, buf, size)); // [cumulative for 12: 36ms]
RETURN_ERR(vfs->LoadFile(path/fntName, buf, size)); // [cumulative for 12: 36ms]
std::istringstream FNTStream(std::string((const char*)buf.get(), size));
int Version;
@ -152,7 +150,7 @@ static LibError UniFont_reload(UniFont* f, const VfsPath& basename, Handle UNUSE
// Load glyph texture
// [cumulative for 12: 20ms]
const VfsPath imgName(basename.string() + L".png");
Handle ht = ogl_tex_load(path/imgName);
Handle ht = ogl_tex_load(vfs, path/imgName);
RETURN_ERR(ht);
(void)ogl_tex_set_filter(ht, GL_NEAREST);
// override is necessary because the GL format is chosen as LUMINANCE,
@ -197,9 +195,9 @@ static LibError UniFont_to_string(const UniFont* f, wchar_t* buf)
}
Handle unifont_load(const VfsPath& pathname, size_t flags)
Handle unifont_load(const PIVFS& vfs, const VfsPath& pathname, size_t flags)
{
return h_alloc(H_UniFont, pathname, flags);
return h_alloc(H_UniFont, vfs, pathname, flags);
}

View File

@ -30,6 +30,7 @@
#include <stdarg.h> // va_list
#include "lib/res/handle.h"
#include "lib/file/vfs/vfs.h"
/**
* Load a font.
@ -37,7 +38,7 @@
* @param pathname path and basename of the font definition file
* (.fnt) and its texture (.png)
**/
extern Handle unifont_load(const VfsPath& pathname, size_t flags = 0);
extern Handle unifont_load(const PIVFS& vfs, const VfsPath& pathname, size_t flags = 0);
/**
* Release a handle to a previously loaded font

View File

@ -154,7 +154,8 @@ struct HDATA
// for statistics
size_t num_derefs;
PIVFS vfs;
VfsPath pathname;
u8 user[HDATA_USER_SIZE];
@ -493,7 +494,7 @@ static Handle reuse_existing_handle(uintptr_t key, H_Type type, size_t flags)
}
static LibError call_init_and_reload(Handle h, H_Type type, HDATA* hd, const VfsPath& pathname, va_list* init_args)
static LibError call_init_and_reload(Handle h, H_Type type, HDATA* hd, const PIVFS& vfs, const VfsPath& pathname, va_list* init_args)
{
LibError err = INFO::OK;
H_VTbl* vtbl = type; // exact same thing but for clarity
@ -508,7 +509,7 @@ static LibError call_init_and_reload(Handle h, H_Type type, HDATA* hd, const Vfs
// catch exception to simplify reload funcs - let them use new()
try
{
err = vtbl->reload(hd->user, pathname, h);
err = vtbl->reload(hd->user, vfs, pathname, h);
if(err == INFO::OK)
warn_if_invalid(hd);
}
@ -522,7 +523,7 @@ static LibError call_init_and_reload(Handle h, H_Type type, HDATA* hd, const Vfs
}
static Handle alloc_new_handle(H_Type type, const VfsPath& pathname, uintptr_t key, size_t flags, va_list* init_args)
static Handle alloc_new_handle(H_Type type, const PIVFS& vfs, const VfsPath& pathname, uintptr_t key, size_t flags, va_list* init_args)
{
ssize_t idx;
HDATA* hd;
@ -542,12 +543,13 @@ static Handle alloc_new_handle(H_Type type, const VfsPath& pathname, uintptr_t k
if(flags & RES_DISALLOW_RELOAD)
hd->disallow_reload = 1;
hd->unique = (flags & RES_UNIQUE) != 0;
hd->vfs = vfs;
hd->pathname = pathname;
if(key && !hd->unique)
key_add(key, h);
LibError err = call_init_and_reload(h, type, hd, pathname, init_args);
LibError err = call_init_and_reload(h, type, hd, vfs, pathname, init_args);
if(err < 0)
goto fail;
@ -565,7 +567,7 @@ fail:
// any further params are passed to type's init routine
Handle h_alloc(H_Type type, const VfsPath& pathname, size_t flags, ...)
Handle h_alloc(H_Type type, const PIVFS& vfs, const VfsPath& pathname, size_t flags, ...)
{
RETURN_ERR(type_validate(type));
@ -580,7 +582,7 @@ Handle h_alloc(H_Type type, const VfsPath& pathname, size_t flags, ...)
// .. need to allocate a new one:
va_list args;
va_start(args, flags);
h = alloc_new_handle(type, pathname, key, flags, &args);
h = alloc_new_handle(type, vfs, pathname, key, flags, &args);
va_end(args);
return h; // alloc_new_handle already does CHECK_ERR
}
@ -721,7 +723,7 @@ LibError h_reload(const VfsPath& pathname)
Handle h = handle(i, hd->tag);
LibError err = hd->type->reload(hd->user, hd->pathname, h);
LibError err = hd->type->reload(hd->user, hd->vfs, hd->pathname, h);
// don't stop if an error is encountered - try to reload them all.
if(err < 0)
{

View File

@ -252,6 +252,8 @@ we could switch H_DEREF to throwing an exception on error.
#include "handle.h"
#endif
#include "lib/file/vfs/vfs.h"
extern void h_mgr_init();
extern void h_mgr_shutdown();
@ -294,7 +296,7 @@ but- has to handle variable params, a bit ugly
struct H_VTbl
{
void (*init)(void* user, va_list);
LibError (*reload)(void* user, const VfsPath& pathname, Handle);
LibError (*reload)(void* user, const PIVFS& vfs, const VfsPath& pathname, Handle);
void (*dtor)(void* user);
LibError (*validate)(const void* user);
LibError (*to_string)(const void* user, wchar_t* buf);
@ -307,14 +309,14 @@ typedef H_VTbl* H_Type;
#define H_TYPE_DEFINE(type)\
/* forward decls */\
static void type##_init(type*, va_list);\
static LibError type##_reload(type*, const VfsPath&, Handle);\
static LibError type##_reload(type*, const PIVFS&, const VfsPath&, Handle);\
static void type##_dtor(type*);\
static LibError type##_validate(const type*);\
static LibError type##_to_string(const type*, wchar_t* buf);\
static H_VTbl V_##type =\
{\
(void (*)(void*, va_list))type##_init,\
(LibError (*)(void*, const VfsPath&, Handle))type##_reload,\
(LibError (*)(void*, const PIVFS&, const VfsPath&, Handle))type##_reload,\
(void (*)(void*))type##_dtor,\
(LibError (*)(const void*))type##_validate,\
(LibError (*)(const void*, wchar_t*))type##_to_string,\
@ -392,7 +394,7 @@ const size_t H_STRING_LEN = 256;
//// user_size is checked to make sure the user data fits in the handle data space.
// dtor is associated with type and called when the object is freed.
// handle data is initialized to 0; optionally, a pointer to it is returned.
extern Handle h_alloc(H_Type type, const VfsPath& pathname, size_t flags = 0, ...);
extern Handle h_alloc(H_Type type, const PIVFS& vfs, const VfsPath& pathname, size_t flags = 0, ...);
extern LibError h_free(Handle& h, H_Type type);

View File

@ -27,8 +27,6 @@
#ifndef INCLUDED_HANDLE
#define INCLUDED_HANDLE
#include "lib/file/vfs/vfs_path.h"
/**
* `handle' representing a reference to a resource (sound, texture, etc.)
*

View File

@ -38,9 +38,7 @@
#include <cfloat>
#include "lib/path_util.h"
#include "../h_mgr.h"
#include "lib/file/vfs/vfs.h"
extern PIVFS g_VFS;
#include "lib/res/h_mgr.h"
// for DLL-load hack in alc_init
@ -825,7 +823,7 @@ if(sd->o) ogg_release(sd->o);
// but that load failed).
static void hsd_list_add(Handle hsd);
static LibError SndData_reload(SndData* sd, const VfsPath& pathname, Handle hsd)
static LibError SndData_reload(SndData* sd, const PIVFS& vfs, const VfsPath& pathname, Handle hsd)
{
// currently only supports OGG; WAV is no longer supported. writing our own loader is infeasible
// due to a seriously watered down spec with many incompatible variants.
@ -847,7 +845,7 @@ static LibError SndData_reload(SndData* sd, const VfsPath& pathname, Handle hsd)
#endif
shared_ptr<u8> file; size_t file_size;
RETURN_ERR(g_VFS->LoadFile(pathname, file, file_size));
RETURN_ERR(vfs->LoadFile(pathname, file, file_size));
ALvoid* al_data = (ALvoid*)file.get();
ALsizei al_size = (ALsizei)file_size;
@ -909,11 +907,11 @@ static LibError SndData_to_string(const SndData* sd, wchar_t* buf)
* or loaded immediately.
* @return Handle or LibError on failure
*/
static Handle snd_data_load(const VfsPath& pathname, bool is_stream)
static Handle snd_data_load(const PIVFS& vfs, const VfsPath& pathname, bool is_stream)
{
debug_assert(!is_stream); // no longer supported
return h_alloc(H_SndData, pathname);
return h_alloc(H_SndData, vfs, pathname);
}
@ -1254,7 +1252,7 @@ static void VSrc_dtor(VSrc* vs)
(void)snd_data_free(vs->hsd);
}
static LibError VSrc_reload(VSrc* vs, const VfsPath& pathname, Handle hvs)
static LibError VSrc_reload(VSrc* vs, const PIVFS& vfs, const VfsPath& pathname, Handle hvs)
{
// cannot wait till play(), need to init here:
// must load OpenAL so that snd_data_load can check for OGG extension.
@ -1272,7 +1270,7 @@ static LibError VSrc_reload(VSrc* vs, const VfsPath& pathname, Handle hvs)
if(fs::extension(pathname) == L".txt")
{
shared_ptr<u8> buf; size_t size;
RETURN_ERR(g_VFS->LoadFile(pathname, buf, size));
RETURN_ERR(vfs->LoadFile(pathname, buf, size));
std::wistringstream def(std::wstring((wchar_t*)buf.get(), (int)size));
def >> dataPathname;
@ -1294,7 +1292,7 @@ static LibError VSrc_reload(VSrc* vs, const VfsPath& pathname, Handle hvs)
// needed so we can snd_free ourselves when done playing.
bool is_stream = (vs->flags & VS_IS_STREAM) != 0;
vs->hsd = snd_data_load(dataPathname, is_stream);
vs->hsd = snd_data_load(vfs, dataPathname, is_stream);
RETURN_ERR(vs->hsd);
return INFO::OK;
@ -1342,14 +1340,14 @@ static LibError VSrc_to_string(const VSrc* vs, wchar_t* buf)
* or loaded immediately.
* @return Handle or LibError on failure
*/
Handle snd_open(const VfsPath& pathname, bool is_stream)
Handle snd_open(const PIVFS& vfs, const VfsPath& pathname, bool is_stream)
{
size_t flags = 0;
if(is_stream)
flags |= VS_IS_STREAM;
// note: RES_UNIQUE forces each instance to get a new resource
// (which is of course what we want).
return h_alloc(H_VSrc, pathname, RES_UNIQUE, flags);
return h_alloc(H_VSrc, vfs, pathname, RES_UNIQUE, flags);
}

View File

@ -29,6 +29,7 @@
#define INCLUDED_SND_MGR
#include "lib/res/handle.h"
#include "lib/file/vfs/vfs.h"
/**
@ -180,7 +181,7 @@ extern LibError snd_set_master_gain(float gain);
* only one instance can be open at a time.
* @return Handle or LibError
**/
extern Handle snd_open(const VfsPath& name, bool stream = false);
extern Handle snd_open(const PIVFS& vfs, const VfsPath& name, bool stream = false);
/**
* close the sound instance. if it was playing, it will be stopped.

View File

@ -1012,6 +1012,31 @@ int SDL_ShowCursor(int toggle)
}
SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode)
{
static SDL_GrabMode prevMode;
if(mode == SDL_GRAB_QUERY)
return prevMode;
prevMode = mode;
if(mode == SDL_GRAB_OFF)
ClipCursor(0);
else
{
RECT clientRect;
WARN_IF_FALSE(GetClientRect(g_hWnd, &clientRect));
POINT upperLeft = { clientRect.left, clientRect.top };
WARN_IF_FALSE(ClientToScreen(g_hWnd, &upperLeft));
POINT lowerRight = { clientRect.right, clientRect.bottom };
WARN_IF_FALSE(ClientToScreen(g_hWnd, &lowerRight));
const RECT screenRect = { upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y };
WARN_IF_FALSE(ClipCursor(&screenRect));
}
return mode;
}
//----------------------------------------------------------------------------
// video resizing/expose

View File

@ -273,8 +273,13 @@ LIB_API int SDL_PushEvent(SDL_Event* ev);
// misc
//
#define SDL_GRAB_ON 0
#define SDL_WM_GrabInput(a)
enum SDL_GrabMode
{
SDL_GRAB_QUERY,
SDL_GRAB_OFF,
SDL_GRAB_ON
};
LIB_API SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode);
#define SDL_GetError() ""

View File

@ -105,6 +105,7 @@ library and IO layer. Read and write are zero-copy.
#define INCLUDED_TEX
#include "lib/res/handle.h"
#include "lib/file/vfs/vfs_path.h"
#include "lib/allocators/dynarray.h"

View File

@ -99,7 +99,7 @@ CVFSFile::~CVFSFile()
{
}
PSRETURN CVFSFile::Load(const VfsPath& filename)
PSRETURN CVFSFile::Load(const PIVFS& vfs, const VfsPath& filename)
{
// Load should never be called more than once, so complain
if (m_Buffer)
@ -108,7 +108,7 @@ PSRETURN CVFSFile::Load(const VfsPath& filename)
return PSRETURN_CVFSFile_AlreadyLoaded;
}
LibError ret = g_VFS->LoadFile(filename, m_Buffer, m_BufferSize);
LibError ret = vfs->LoadFile(filename, m_Buffer, m_BufferSize);
if (ret != INFO::OK)
{
LOGERROR(L"CVFSFile: file %ls couldn't be opened (vfs_load: %ld)", filename.string().c_str(), ret);

View File

@ -70,7 +70,7 @@ public:
// Returns either PSRETURN_OK or PSRETURN_CVFSFile_LoadFailed.
// Dies if a file has already been successfully loaded.
PSRETURN Load(const VfsPath& filename);
PSRETURN Load(const PIVFS& vfs, const VfsPath& filename);
// These die if called when no file has been successfully loaded.
const u8* GetBuffer() const;

View File

@ -16,12 +16,12 @@
*/
#include "precompiled.h"
#include "Font.h"
#include "ps/ConfigDB.h"
#include "lib/res/graphics/unifont.h"
#include "ps/ConfigDB.h"
#include "ps/Filesystem.h"
#include "ps/CLogger.h"
#define LOG_CATEGORY L"graphics"
@ -43,12 +43,12 @@ CFont::CFont(const wchar_t* name)
CConfigValue* fontFilenameVar = g_ConfigDB.GetValue(CFG_USER, fontName);
if (fontFilenameVar && fontFilenameVar->GetString(fontFilename))
{
h = unifont_load(CStrW(fontFilename));
h = unifont_load(g_VFS, CStrW(fontFilename));
}
else
{
// Not found in the config file -- try it as a simple filename
h = unifont_load(name);
h = unifont_load(g_VFS, name);
// Found it
if (h > 0)
@ -56,7 +56,7 @@ CFont::CFont(const wchar_t* name)
// Not found as a font -- give up and use the default.
LOG_ONCE(CLogger::Error, LOG_CATEGORY, L"Failed to find font '%ls'", name);
h = unifont_load(DefaultFont);
h = unifont_load(g_VFS, DefaultFont);
// Assume this worked
}
}

View File

@ -272,9 +272,9 @@ void Render()
// Draw the cursor (or set the Windows cursor, on Windows)
CStrW cursorName = g_CursorName;
if (cursorName.empty())
cursor_draw(NULL, g_mouse_x, g_mouse_y);
cursor_draw(g_VFS, NULL, g_mouse_x, g_yres-g_mouse_y);
else
cursor_draw(cursorName.c_str(), g_mouse_x, g_mouse_y);
cursor_draw(g_VFS, cursorName.c_str(), g_mouse_x, g_yres-g_mouse_y);
// restore
glMatrixMode(GL_PROJECTION);
@ -489,7 +489,7 @@ static void ShutdownPs()
SAFE_DELETE(g_Console);
// disable the special Windows cursor, or free textures for OGL cursors
cursor_draw(0, g_mouse_x, g_mouse_y);
cursor_draw(g_VFS, 0, g_mouse_x, g_yres-g_mouse_y);
// Unload the real language (since it depends on the scripting engine,
// which is going to be killed later) and use the English fallback messages

View File

@ -90,14 +90,14 @@ XMLWriter_File::XMLWriter_File()
m_Data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}
bool XMLWriter_File::StoreVFS(const VfsPath& pathname)
bool XMLWriter_File::StoreVFS(const PIVFS& vfs, const VfsPath& pathname)
{
if (m_LastElement) debug_warn(L"ERROR: Saving XML while an element is still open");
const size_t size = m_Data.length();
shared_ptr<u8> data = io_Allocate(size);
cpu_memcpy(data.get(), m_Data.data(), size);
LibError ret = g_VFS->CreateFile(pathname, data, size);
LibError ret = vfs->CreateFile(pathname, data, size);
if (ret < 0)
{
LOG(CLogger::Error, LOG_CATEGORY, L"Error saving XML data through VFS: %ld", ret);

View File

@ -93,7 +93,7 @@ end of XMLWriter.cpp.
// Create a VFS file from the XML data.
// Returns true on success, false (and logs an error) on failure.
#define XML_StoreVFS(pathname) xml_file_.StoreVFS(pathname)
#define XML_StoreVFS(vfs, pathname) xml_file_.StoreVFS(vfs, pathname)
// Returns the contents of the XML file as a UTF-8 byte stream in a const CStr&
// string. (Use CStr::FromUTF8 to get a Unicode string back.)
@ -101,7 +101,7 @@ end of XMLWriter.cpp.
#include "ps/CStr.h"
#include "lib/file/vfs/vfs_path.h"
#include "lib/file/vfs/vfs.h"
class XMLWriter_Element;
@ -114,7 +114,7 @@ public:
void Comment(const char* text);
bool StoreVFS(const VfsPath& pathname);
bool StoreVFS(const PIVFS& vfs, const VfsPath& pathname);
const CStr& GetOutput();
private:

View File

@ -96,7 +96,7 @@ void CXeromyces::GetXMBPath(const PIVFS& vfs, const VfsPath& xmlFilename, const
xmbActualPath = VfsPath(L"cache/mods") / modName / L"xmb" / xmbFilename;
}
PSRETURN CXeromyces::Load(const VfsPath& filename)
PSRETURN CXeromyces::Load(const PIVFS& vfs, const VfsPath& filename)
{
debug_assert(g_XeromycesStarted);
@ -109,7 +109,7 @@ PSRETURN CXeromyces::Load(const VfsPath& filename)
// Get some data about the .xml file
FileInfo fileInfo;
if (g_VFS->GetFileInfo(filename, &fileInfo) < 0)
if (vfs->GetFileInfo(filename, &fileInfo) < 0)
{
LOG(CLogger::Error, LOG_CATEGORY, L"CXeromyces: Failed to stat XML file %ls", filename.string().c_str());
return PSRETURN_Xeromyces_XMLOpenFailed;
@ -142,12 +142,12 @@ PSRETURN CXeromyces::Load(const VfsPath& filename)
VfsPath xmbFilename = change_extension(filename, suffix);
VfsPath xmbPath;
GetXMBPath(g_VFS, filename, xmbFilename, xmbPath);
GetXMBPath(vfs, filename, xmbFilename, xmbPath);
// If the file exists, use it
if (FileExists(xmbPath))
{
if (ReadXMBFile(xmbPath))
if (ReadXMBFile(vfs, xmbPath))
return PSRETURN_OK;
// (no longer return PSRETURN_Xeromyces_XMLOpenFailed here because
// failure legitimately happens due to partially-written XMB files.)
@ -157,7 +157,7 @@ PSRETURN CXeromyces::Load(const VfsPath& filename)
// XMB isn't up to date with the XML, so rebuild it:
CVFSFile input;
if (input.Load(filename))
if (input.Load(vfs, filename))
{
LOG(CLogger::Error, LOG_CATEGORY, L"CXeromyces: Failed to open XML file %ls", filename.string().c_str());
return PSRETURN_Xeromyces_XMLOpenFailed;
@ -178,7 +178,7 @@ PSRETURN CXeromyces::Load(const VfsPath& filename)
xmlFreeDoc(doc);
// Save the file to disk, so it can be loaded quickly next time
g_VFS->CreateFile(xmbPath, writeBuffer.Data(), writeBuffer.Size());
vfs->CreateFile(xmbPath, writeBuffer.Data(), writeBuffer.Size());
m_XMBBuffer = writeBuffer.Data(); // add a reference
@ -189,10 +189,10 @@ PSRETURN CXeromyces::Load(const VfsPath& filename)
return PSRETURN_OK;
}
bool CXeromyces::ReadXMBFile(const VfsPath& filename)
bool CXeromyces::ReadXMBFile(const PIVFS& vfs, const VfsPath& filename)
{
size_t size;
if(g_VFS->LoadFile(filename, m_XMBBuffer, size) < 0)
if(vfs->LoadFile(filename, m_XMBBuffer, size) < 0)
return false;
debug_assert(size >= 4); // make sure it's at least got the initial header

View File

@ -45,7 +45,7 @@ class CXeromyces : public XMBFile
friend class TestXeroXMB;
public:
// Load from an XML file (with invisible XMB caching).
PSRETURN Load(const VfsPath& filename);
PSRETURN Load(const PIVFS& vfs, const VfsPath& filename);
// Load from an in-memory XML string (with no caching)
PSRETURN LoadString(const char* xml);
@ -62,7 +62,7 @@ private:
// Find out write location of the XMB file corresponding to xmlFilename
static void GetXMBPath(const PIVFS& vfs, const VfsPath& xmlFilename, const VfsPath& xmbFilename, VfsPath& xmbActualPath);
bool ReadXMBFile(const VfsPath& filename);
bool ReadXMBFile(const PIVFS& vfs, const VfsPath& filename);
static PSRETURN CreateXMB(const xmlDocPtr doc, WriteBuffer& writeBuffer);

View File

@ -68,7 +68,7 @@ bool I18n::LoadLanguage(const char* name)
for (size_t i = 0; i < pathnames.size(); i++)
{
CVFSFile strings;
if (! (strings.Load(pathnames[i]) == PSRETURN_OK && locale->LoadStrings((const char*)strings.GetBuffer())))
if (! (strings.Load(g_VFS, pathnames[i]) == PSRETURN_OK && locale->LoadStrings((const char*)strings.GetBuffer())))
{
LOG(CLogger::Error, LOG_CATEGORY, L"Error opening language string file '%ls'", pathnames[i].string().c_str());
return false;
@ -81,7 +81,7 @@ bool I18n::LoadLanguage(const char* name)
for (size_t i = 0; i < pathnames.size(); i++)
{
CVFSFile strings;
if (! (strings.Load(pathnames[i]) == PSRETURN_OK && locale->LoadDictionary((const char*)strings.GetBuffer())))
if (! (strings.Load(g_VFS, pathnames[i]) == PSRETURN_OK && locale->LoadDictionary((const char*)strings.GetBuffer())))
{
LOG(CLogger::Error, LOG_CATEGORY, L"Error opening language string file '%ls'", pathnames[i].string().c_str());
return false;
@ -96,7 +96,7 @@ bool I18n::LoadLanguage(const char* name)
const wchar_t* pathname = pathnames[i].string().c_str();
CStr8 pathname8(pathname);
CVFSFile strings;
if (! (strings.Load(pathname) == PSRETURN_OK
if (! (strings.Load(g_VFS, pathname) == PSRETURN_OK
&&
locale->LoadFunctions(
(const char*)strings.GetBuffer(),

View File

@ -20,6 +20,7 @@
#include "lib/ogl.h"
#include "lib/res/graphics/ogl_shader.h"
#include "ps/CLogger.h"
#include "ps/Filesystem.h"
#include "renderer/Renderer.h"
#include "renderer/RenderPathVertexShader.h"
@ -77,42 +78,42 @@ bool RenderPathVertexShader::Init()
if (!g_Renderer.m_Caps.m_VertexShader)
return false;
m_ModelLight = ogl_program_load(L"shaders/model_light.xml");
m_ModelLight = ogl_program_load(g_VFS, L"shaders/model_light.xml");
if (m_ModelLight < 0)
{
LOG(CLogger::Warning, LOG_CATEGORY, L"Failed to load shaders/model_light.xml: %i\n", (int)m_ModelLight);
return false;
}
m_ModelLightP = ogl_program_load(L"shaders/model_lightp.xml");
m_ModelLightP = ogl_program_load(g_VFS, L"shaders/model_lightp.xml");
if (m_ModelLightP < 0)
{
LOG(CLogger::Warning, LOG_CATEGORY, L"Failed to load shaders/model_lightp.xml: %i\n", (int)m_ModelLightP);
return false;
}
m_InstancingLight = ogl_program_load(L"shaders/instancing_light.xml");
m_InstancingLight = ogl_program_load(g_VFS, L"shaders/instancing_light.xml");
if (m_InstancingLight < 0)
{
LOG(CLogger::Warning, LOG_CATEGORY, L"Failed to load shaders/instancing_light.xml: %i\n", (int)m_InstancingLight);
return false;
}
m_InstancingLightP = ogl_program_load(L"shaders/instancing_lightp.xml");
m_InstancingLightP = ogl_program_load(g_VFS, L"shaders/instancing_lightp.xml");
if (m_InstancingLightP < 0)
{
LOG(CLogger::Warning, LOG_CATEGORY, L"Failed to load shaders/instancing_lightp.xml: %i\n", (int)m_InstancingLightP);
return false;
}
m_Instancing = ogl_program_load(L"shaders/instancing.xml");
m_Instancing = ogl_program_load(g_VFS, L"shaders/instancing.xml");
if (m_Instancing < 0)
{
LOG(CLogger::Warning, LOG_CATEGORY, L"Failed to load shaders/instancing.xml: %i\n", (int)m_Instancing);
return false;
}
m_InstancingP = ogl_program_load(L"shaders/instancingp.xml");
m_InstancingP = ogl_program_load(g_VFS, L"shaders/instancingp.xml");
if (m_InstancingP < 0)
{
LOG(CLogger::Warning, LOG_CATEGORY, L"Failed to load shaders/instancingp.xml: %i\n", (int)m_InstancingP);

View File

@ -1466,7 +1466,7 @@ bool CRenderer::LoadTexture(CTexture* texture,int wrapflags)
return h==errorhandle ? true : false;
}
h = ogl_tex_load(texture->GetName());
h = ogl_tex_load(g_VFS, texture->GetName());
if (h <= 0)
{
LOG(CLogger::Error, LOG_CATEGORY, L"LoadTexture failed on \"%ls\"", texture->GetName().string().c_str());
@ -1585,7 +1585,7 @@ int CRenderer::LoadAlphaMaps()
{
// note: these individual textures can be discarded afterwards;
// we cache the composite.
textures[i] = ogl_tex_load(path/fnames[i]);
textures[i] = ogl_tex_load(g_VFS, path/fnames[i]);
RETURN_ERR(textures[i]);
// quick hack: we require plain RGB(A) format, so convert to that.
@ -1665,7 +1665,7 @@ ogl_tex_transform_to(textures[i], flags & ~TEX_DXT);
// upload the composite texture
Tex t;
(void)tex_wrap(total_w, total_h, 24, 0, data, 0, &t);
m_hCompositeAlphaMap = ogl_tex_wrap(&t, key);
m_hCompositeAlphaMap = ogl_tex_wrap(&t, g_VFS, key);
(void)ogl_tex_set_filter(m_hCompositeAlphaMap, GL_LINEAR);
(void)ogl_tex_set_wrap (m_hCompositeAlphaMap, GL_CLAMP_TO_EDGE);
int ret = ogl_tex_upload(m_hCompositeAlphaMap, 0, 0, GL_INTENSITY);

View File

@ -88,7 +88,7 @@ LibError SkyManager::LoadSkyTexture(size_t index)
{
wchar_t filename[PATH_MAX];
swprintf_s(filename, ARRAY_SIZE(filename), L"art/textures/skies/%ls/%ls.dds", m_SkySet.c_str(), s_imageNames[index]);
Handle ht = ogl_tex_load(filename);
Handle ht = ogl_tex_load(g_VFS, filename);
if(ht <= 0)
{
LOG(CLogger::Error, LOG_CATEGORY, L"SkyManager::LoadSkyTexture failed on \"%ls\"", filename);

View File

@ -30,6 +30,7 @@
#include "maths/MathUtil.h"
#include "ps/Filesystem.h"
#include "ps/CLogger.h"
#include "ps/Game.h"
#include "ps/Profile.h"
@ -420,7 +421,7 @@ void TerrainRenderer::RenderWater()
// If we're using fancy water, make sure its shader is loaded
if(fancy && !m->fancyWaterShader)
{
Handle h = ogl_program_load(L"shaders/water_high.xml");
Handle h = ogl_program_load(g_VFS, L"shaders/water_high.xml");
if (h < 0)
{
LOG(CLogger::Error, LOG_CATEGORY, L"Failed to load water shader. Falling back to non-fancy water.\n");

View File

@ -28,6 +28,7 @@
#include "maths/MathUtil.h"
#include "ps/Filesystem.h"
#include "ps/CLogger.h"
#include "ps/Loader.h"
@ -111,7 +112,7 @@ int WaterManager::LoadWaterTextures()
while (cur_loading_water_tex < num_textures)
{
swprintf_s(pathname, ARRAY_SIZE(pathname), L"art/textures/animated/water/%ls/diffuse%02d.dds", water_type, (int)cur_loading_water_tex+1);
Handle ht = ogl_tex_load(pathname);
Handle ht = ogl_tex_load(g_VFS, pathname);
if (ht <= 0)
{
LOG(CLogger::Error, LOG_CATEGORY, L"LoadWaterTextures failed on \"%ls\"", pathname);
@ -127,7 +128,7 @@ int WaterManager::LoadWaterTextures()
while (cur_loading_normal_map < num_normal_maps)
{
swprintf_s(pathname, ARRAY_SIZE(pathname), L"art/textures/animated/water/%ls/normal%02d.dds", water_type, (int)cur_loading_normal_map+1);
Handle ht = ogl_tex_load(pathname);
Handle ht = ogl_tex_load(g_VFS, pathname);
if (ht <= 0)
{
LOG(CLogger::Error, LOG_CATEGORY, L"LoadWaterTextures failed on \"%ls\"", pathname);

View File

@ -70,7 +70,7 @@ public:
VfsPath path = VfsPath(L"simulation/templates/") / name;
CXeromyces xero;
PSRETURN ok = xero.Load(path);
PSRETURN ok = xero.Load(g_VFS, path);
if (ok != PSRETURN_OK)
return ret; // (Xeromyces already logged an error)

View File

@ -275,7 +275,7 @@ bool CCmpTemplateManager::LoadTemplateFile(const std::string& templateName, int
VfsPath path = VfsPath(TEMPLATE_ROOT) / (std::wstring)CStrW(templateName + ".xml");
CXeromyces xero;
PSRETURN ok = xero.Load(path);
PSRETURN ok = xero.Load(g_VFS, path);
if (ok != PSRETURN_OK)
return false; // (Xeromyces already logged an error with the full filename)

View File

@ -39,7 +39,7 @@ public:
{
std::wstring name = path.external_file_string();
CVFSFile file;
TS_ASSERT_EQUALS(file.Load(path), PSRETURN_OK);
TS_ASSERT_EQUALS(file.Load(g_VFS, path), PSRETURN_OK);
CStr content = file.GetAsString();
std::wstring wcontent(content.begin(), content.end());
TSM_ASSERT(L"Running script "+name, scriptInterface.LoadScript(name, wcontent));

View File

@ -107,7 +107,7 @@ bool CComponentManager::LoadScript(const std::wstring& filename, bool hotload)
{
m_CurrentlyHotloading = hotload;
CVFSFile file;
PSRETURN loadOk = file.Load(filename);
PSRETURN loadOk = file.Load(g_VFS, filename);
debug_assert(loadOk == PSRETURN_OK); // TODO
std::wstring content(file.GetBuffer(), file.GetBuffer() + file.GetBufferSize()); // TODO: encodings etc
bool ok = m_ScriptInterface.LoadScript(filename, content);

View File

@ -21,11 +21,12 @@
#include "lib/res/sound/snd_mgr.h"
#include "lib/res/h_mgr.h" // h_filename
#include "ps/Filesystem.h"
JSI_Sound::JSI_Sound(const VfsPath& pathname)
{
m_Handle = snd_open(pathname);
m_Handle = snd_open(g_VFS, pathname);
// special-case to avoid throwing exceptions if quickstart has
// disabled sound: set a flag queried by Construct; the object will

View File

@ -29,9 +29,12 @@
#include <algorithm>
#include "lib/rand.h"
#include "ps/XML/Xeromyces.h"
#include "ps/CLogger.h"
#include "lib/rand.h"
#include "ps/Filesystem.h"
#define LOG_CATEGORY L"audio"
@ -131,7 +134,7 @@ void CSoundGroup::PlayNext(const CVector3D& position)
{
// load up replacement file
const VfsPath pathname(m_filepath/m_intensity_file);
m_hReplacement = snd_open(pathname);
m_hReplacement = snd_open(g_VFS, pathname);
if(m_hReplacement < 0)
{
HandleError(L"PlayNext: snd_open for replacement file failed", pathname, (LibError)m_hReplacement);
@ -152,7 +155,7 @@ void CSoundGroup::PlayNext(const CVector3D& position)
m_index = (size_t)rand(0, (size_t)filenames.size());
// (note: previously snd_group[m_index] was used in place of hs)
const VfsPath pathname(m_filepath/filenames[m_index]);
Handle hs = snd_open(pathname);
Handle hs = snd_open(g_VFS, pathname);
if(hs < 0)
{
HandleError(L"PlayNext: snd_open failed", pathname, (LibError)hs);
@ -229,7 +232,7 @@ void CSoundGroup::Update(float TimeSinceLastFrame)
bool CSoundGroup::LoadSoundGroup(const VfsPath& pathnameXML)
{
CXeromyces XeroFile;
if (XeroFile.Load(pathnameXML) != PSRETURN_OK)
if (XeroFile.Load(g_VFS, pathnameXML) != PSRETURN_OK)
return false;
// Define elements used in XML file