Skip to content

Commit

Permalink
added mod system. Closes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
oy committed Oct 6, 2010
1 parent a62a741 commit 3a98f7a
Show file tree
Hide file tree
Showing 36 changed files with 341 additions and 213 deletions.
2 changes: 2 additions & 0 deletions scripts/make_release.py
Expand Up @@ -61,6 +61,7 @@ def copydir(src, dst, excl=[]):
print "adding files"
shutil.copy("readme.txt", package_dir)
shutil.copy("license.txt", package_dir)
shutil.copy("storage.cfg", package_dir)

if include_data and not use_bundle:
os.mkdir(os.path.join(package_dir, "data"))
Expand Down Expand Up @@ -133,6 +134,7 @@ def copydir(src, dst, excl=[]):
os.mkdir(serverbundle_resource_dir)
os.mkdir(os.path.join(serverbundle_resource_dir, "data"))
os.mkdir(os.path.join(serverbundle_resource_dir, "data/maps"))
os.mkdir(os.path.join(serverbundle_resource_dir, "data/mapres"))
copydir("data/maps", serverbundle_resource_dir)
shutil.copy("other/icons/Teeworlds_srv.icns", serverbundle_resource_dir)
shutil.copy(name+"_srv"+exe_ext, serverbundle_bin_dir)
Expand Down
5 changes: 1 addition & 4 deletions src/engine/client.h
Expand Up @@ -73,7 +73,7 @@ class IClient : public IInterface
virtual void Connect(const char *pAddress) = 0;
virtual void Disconnect() = 0;
virtual void Quit() = 0;
virtual const char *DemoPlayer_Play(const char *pFilename) = 0;
virtual const char *DemoPlayer_Play(const char *pFilename, int StorageType) = 0;
virtual void DemoRecorder_Start(const char *pFilename) = 0;

// networking
Expand Down Expand Up @@ -121,9 +121,6 @@ class IClient : public IInterface
return SendMsg(&Packer, Flags);
}

//
virtual const char *UserDirectory() = 0;

//
virtual const char *ErrorString() = 0;
virtual const char *LatestVersion() = 0;
Expand Down
17 changes: 5 additions & 12 deletions src/engine/client/client.cpp
Expand Up @@ -585,7 +585,7 @@ void CClient::ServerInfoRequest()

int CClient::LoadData()
{
m_DebugFont = Graphics()->LoadTexture("debug_font.png", CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_NORESAMPLE);
m_DebugFont = Graphics()->LoadTexture("debug_font.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_NORESAMPLE);
return 1;
}

Expand Down Expand Up @@ -990,7 +990,7 @@ void CClient::ProcessPacket(CNetChunk *pPacket)

m_MapdownloadChunk = 0;
str_copy(m_aMapdownloadName, pMap, sizeof(m_aMapdownloadName));
m_MapdownloadFile = Storage()->OpenFile(m_aMapdownloadFilename, IOFLAG_WRITE);
m_MapdownloadFile = Storage()->OpenFile(m_aMapdownloadFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
m_MapdownloadCrc = MapCrc;
m_MapdownloadTotalsize = -1;
m_MapdownloadAmount = 0;
Expand Down Expand Up @@ -1537,13 +1537,6 @@ void CClient::Update()
m_ServerBrowser.Update();
}

const char *CClient::UserDirectory()
{
static char saPath[1024] = {0};
fs_storage_path("Teeworlds", saPath, sizeof(saPath));
return saPath;
}

void CClient::VersionUpdate()
{
if(m_VersionInfo.m_State == 0)
Expand Down Expand Up @@ -1871,7 +1864,7 @@ void CClient::Con_AddFavorite(IConsole::IResult *pResult, void *pUserData)
pSelf->m_ServerBrowser.AddFavorite(Addr);
}

const char *CClient::DemoPlayer_Play(const char *pFilename)
const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
{
int Crc;
const char *pError;
Expand All @@ -1881,7 +1874,7 @@ const char *CClient::DemoPlayer_Play(const char *pFilename)
// try to start playback
m_DemoPlayer.SetListner(this);

if(m_DemoPlayer.Load(Storage(), m_pConsole, pFilename))
if(m_DemoPlayer.Load(Storage(), m_pConsole, pFilename, StorageType))
return "error loading demo";

// load map
Expand Down Expand Up @@ -1926,7 +1919,7 @@ const char *CClient::DemoPlayer_Play(const char *pFilename)
void CClient::Con_Play(IConsole::IResult *pResult, void *pUserData)
{
CClient *pSelf = (CClient *)pUserData;
pSelf->DemoPlayer_Play(pResult->GetString(0));
pSelf->DemoPlayer_Play(pResult->GetString(0), IStorage::TYPE_ALL);
}

void CClient::DemoRecorder_Start(const char *pFilename)
Expand Down
4 changes: 1 addition & 3 deletions src/engine/client/client.h
Expand Up @@ -259,8 +259,6 @@ class CClient : public IClient, public CDemoPlayer::IListner

void Update();

virtual const char *UserDirectory();

void InitEngine(const char *pAppname);
void RegisterInterfaces();
void InitInterfaces();
Expand All @@ -283,7 +281,7 @@ class CClient : public IClient, public CDemoPlayer::IListner

void RegisterCommands();

const char *DemoPlayer_Play(const char *pFilename);
const char *DemoPlayer_Play(const char *pFilename, int StorageType);
void DemoRecorder_Start(const char *pFilename);

virtual class CEngine *Engine() { return &m_Engine; }
Expand Down
12 changes: 6 additions & 6 deletions src/engine/client/graphics.cpp
Expand Up @@ -354,15 +354,15 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo
}

// simple uncompressed RGBA loaders
int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StoreFormat, int Flags)
int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags)
{
int l = str_length(pFilename);
int Id;
CImageInfo Img;

if(l < 3)
return -1;
if(LoadPNG(&Img, pFilename))
if(LoadPNG(&Img, pFilename, StorageType))
{
if (StoreFormat == CImageInfo::FORMAT_AUTO)
StoreFormat = Img.m_Format;
Expand All @@ -375,7 +375,7 @@ int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StoreFormat, int Fl
return m_InvalidTexture;
}

int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename)
int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType)
{
char aCompleteFilename[512];
unsigned char *pBuffer;
Expand All @@ -384,7 +384,7 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename)
// open file for reading
png_init(0,0); // ignore_convention

IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, aCompleteFilename, sizeof(aCompleteFilename));
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType, aCompleteFilename, sizeof(aCompleteFilename));
if(File)
io_close(File);
else
Expand Down Expand Up @@ -450,7 +450,7 @@ void CGraphics_OpenGL::ScreenshotDirect(const char *pFilename)
char aWholePath[1024];
png_t Png; // ignore_convention

IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, aWholePath, sizeof(aWholePath));
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE, aWholePath, sizeof(aWholePath));
if(File)
io_close(File);

Expand Down Expand Up @@ -898,7 +898,7 @@ void CGraphics_SDL::Swap()
{
IOHANDLE io;
str_format(aFilename, sizeof(aFilename), "screenshots/screenshot%s-%05d.png", aDate, Index);
io = m_pStorage->OpenFile(aFilename, IOFLAG_READ);
io = m_pStorage->OpenFile(aFilename, IOFLAG_READ, IStorage::TYPE_SAVE);
if(io)
io_close(io);
else
Expand Down
4 changes: 2 additions & 2 deletions src/engine/client/graphics.h
Expand Up @@ -87,8 +87,8 @@ class CGraphics_OpenGL : public IEngineGraphics
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags);

// simple uncompressed RGBA loaders
virtual int LoadTexture(const char *pFilename, int StoreFormat, int Flags);
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename);
virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags);
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType);

void ScreenshotDirect(const char *pFilename);

Expand Down
2 changes: 1 addition & 1 deletion src/engine/client/sound.cpp
Expand Up @@ -325,7 +325,7 @@ int CSound::LoadWV(const char *pFilename)
if(!m_pStorage)
return -1;

ms_File = m_pStorage->OpenFile(pFilename, IOFLAG_READ); // TODO: use system.h stuff for this
ms_File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL);
if(!ms_File)
{
dbg_msg("sound/wv", "failed to open %s", pFilename);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/client/text.cpp
Expand Up @@ -70,7 +70,7 @@ struct CFontSizeData
class CFont
{
public:
char m_aFilename[128];
char m_aFilename[512];
FT_Face m_FtFace;
CFontSizeData m_aSizes[NUM_FONT_SIZES];
};
Expand Down
4 changes: 2 additions & 2 deletions src/engine/graphics.h
Expand Up @@ -74,10 +74,10 @@ class IGraphics : public IInterface
virtual void BlendAdditive() = 0;
virtual int MemoryUsage() const = 0;

virtual int LoadPNG(CImageInfo *pImg, const char *pFilename) =0;
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) =0;
virtual int UnloadTexture(int Index) = 0;
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) = 0;
virtual int LoadTexture(const char *pFilename, int StoreFormat, int Flags) = 0;
virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags) = 0;
virtual void TextureSet(int TextureID) = 0;

struct CLineItem
Expand Down
2 changes: 1 addition & 1 deletion src/engine/server/server.cpp
Expand Up @@ -1043,7 +1043,7 @@ int CServer::LoadMap(const char *pMapName)

// load compelate map into memory for download
{
IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_READ);
IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL);
m_CurrentMapSize = (int)io_length(File);
if(m_pCurrentMapData)
mem_free(m_pCurrentMapData);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/config.cpp
Expand Up @@ -74,7 +74,7 @@ class CConfig : public IConfig
{
if(!m_pStorage)
return;
m_ConfigFile = m_pStorage->OpenFile("settings.cfg", IOFLAG_WRITE);
m_ConfigFile = m_pStorage->OpenFile("settings.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);

if(!m_ConfigFile)
return;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/console.cpp
Expand Up @@ -300,7 +300,7 @@ void CConsole::ExecuteFile(const char *pFilename)
m_pFirstExec = &ThisFile;

// exec the file
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ);
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL);

char aBuf[256];
if(File)
Expand Down
6 changes: 3 additions & 3 deletions src/engine/shared/datafile.cpp
Expand Up @@ -65,11 +65,11 @@ struct CDatafile
char *m_pData;
};

bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename)
bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int StorageType)
{
dbg_msg("datafile", "loading. filename='%s'", pFilename);

IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ);
IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
if(!File)
{
dbg_msg("datafile", "could not open '%s'", pFilename);
Expand Down Expand Up @@ -394,7 +394,7 @@ unsigned CDataFileReader::Crc()
bool CDataFileWriter::Open(class IStorage *pStorage, const char *pFilename)
{
dbg_assert(!m_File, "a file already exists");
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE);
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(!m_File)
return false;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/datafile.h
Expand Up @@ -12,7 +12,7 @@ class CDataFileReader

bool IsOpen() const { return m_pDataFile != 0; }

bool Open(class IStorage *pStorage, const char *pFilename);
bool Open(class IStorage *pStorage, const char *pFilename, int StorageType);
bool Close();

void *GetData(int Index);
Expand Down
14 changes: 7 additions & 7 deletions src/engine/shared/demo.cpp
Expand Up @@ -40,12 +40,12 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
char aMapFilename[128];
// try the normal maps folder
str_format(aMapFilename, sizeof(aMapFilename), "maps/%s.map", pMap);
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ);
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL);
if(!MapFile)
{
// try the downloaded maps
str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", pMap, Crc);
MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ);
MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL);
}
if(!MapFile)
{
Expand All @@ -55,7 +55,7 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
return -1;
}

m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE);
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(!m_File)
{
io_close(MapFile);
Expand Down Expand Up @@ -513,10 +513,10 @@ void CDemoPlayer::Unpause()
}
}

int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename)
int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType)
{
m_pConsole = pConsole;
m_File = pStorage->OpenFile(pFilename, IOFLAG_READ);
m_File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
if(!m_File)
{
char aBuf[256];
Expand Down Expand Up @@ -566,7 +566,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
int Crc = (m_Info.m_Header.m_aCrc[0]<<24) | (m_Info.m_Header.m_aCrc[1]<<16) | (m_Info.m_Header.m_aCrc[2]<<8) | (m_Info.m_Header.m_aCrc[3]);
char aMapFilename[128];
str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", m_Info.m_Header.m_aMap, Crc);
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ);
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL);

if(MapFile)
{
Expand All @@ -580,7 +580,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
io_read(m_File, pMapData, MapSize);

// save map
MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE);
MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
io_write(MapFile, pMapData, MapSize);
io_close(MapFile);

Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/demo.h
Expand Up @@ -103,7 +103,7 @@ class CDemoPlayer : public IDemoPlayer

void SetListner(IListner *pListner);

int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename);
int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType);
int Play();
void Pause();
void Unpause();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/map.cpp
Expand Up @@ -28,7 +28,7 @@ class CMap : public IEngineMap
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
if(!pStorage)
return false;
return m_DataFile.Open(pStorage, pMapName);
return m_DataFile.Open(pStorage, pMapName, IStorage::TYPE_ALL);
}

virtual bool IsLoaded()
Expand Down
4 changes: 2 additions & 2 deletions src/engine/shared/masterserver.cpp
Expand Up @@ -119,7 +119,7 @@ class CMasterServer : public IEngineMasterServer
return -1;

// try to open file
File = pStorage->OpenFile("masters.cfg", IOFLAG_READ);
File = pStorage->OpenFile("masters.cfg", IOFLAG_READ, IStorage::TYPE_SAVE);
if(!File)
return -1;

Expand Down Expand Up @@ -165,7 +165,7 @@ class CMasterServer : public IEngineMasterServer
return -1;

// try to open file
File = pStorage->OpenFile("masters.cfg", IOFLAG_WRITE);
File = pStorage->OpenFile("masters.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(!File)
return -1;

Expand Down

0 comments on commit 3a98f7a

Please sign in to comment.