In CS\Plugins\autoloader\csAutoloader.cpp:
Code:
/*
Copyright (C) 2006 by Joshua Warner
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "..\..\include\cssysdef.h"
void csAutoThreadedLoad::Run(csAutoLoader* aloader)
{
csRef<iVFS> vfs;
//TODO:initialize vfs.
csAutoLoaderJob& job;
//aloader->current->SetComplete(0);
//aloader->current->SetTotal(aloader->jobs.GetSize());
csArray<csAutoLoaderJob>::Iterator it;
it = aloader->jobs->GetIterator();
while(it.HasNext())
{
jobs = it.Next();
csRef<iFile> file = vfs->Open(job.fname, VFS_FILE_READ);
job.data = file->GetAllData();
//aloader->current->Step();
job.done = true;
}
//aloader->current->Finished();
aloader->jobs.Empty();
aloading->loading = false;
}
csAutoLoader::csAutoLoader()
{
loading = false;
}
void csAutoLoader::AddJob(const char* name, const char* fname)
{
csAutoLoaderJob job;
job.fname = new char[strlen(fname)];
job.name = new char[strlen(name)];
strcpy(job.fname,fname);
strcpy(job.name,name);
jobs.Push(job);
}
void csAutoLoader::RemoveJob(const char* name)
{
int i;
for(i = 0;i<jobs.GetSize();i++)
{
if(strcmp(jobs.GetAt(i).name, name)==0)
{
csAutoLoaderJob job = jobs.GetAt(i);
delete [] job.fname;
delete [] job.name;
delete [] job.type;
jobs.DeleteIndex(i);
}
}
}
void csAutoLoader::StartLoad(/*iAutoLoaderProgress& progress = internal*/)
{
//current = progress;
loading = true;
csRef<csThread> thread = csThread::Create(new csAutoThreadedLoad);
thread->Start();
}
bool csAutoLoader::Finish()
{
if(!loading)
{
csRef<iLoader> loader;
//TODO: initialize loader
csArray<csAutoLoaderJob>::Iterator it;
it = jobs->GetIterator();
int i = 0;
while(it.HasNext())
{
job = it.Next();
if(job.done)
{
if(loader->Load(&job.data))
jobs->DeleteIndex(i);
}
i++;
}
return true;
}
else return false;
}
Copyright (C) 2006 by Joshua Warner
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "..\..\include\cssysdef.h"
void csAutoThreadedLoad::Run(csAutoLoader* aloader)
{
csRef<iVFS> vfs;
//TODO:initialize vfs.
csAutoLoaderJob& job;
//aloader->current->SetComplete(0);
//aloader->current->SetTotal(aloader->jobs.GetSize());
csArray<csAutoLoaderJob>::Iterator it;
it = aloader->jobs->GetIterator();
while(it.HasNext())
{
jobs = it.Next();
csRef<iFile> file = vfs->Open(job.fname, VFS_FILE_READ);
job.data = file->GetAllData();
//aloader->current->Step();
job.done = true;
}
//aloader->current->Finished();
aloader->jobs.Empty();
aloading->loading = false;
}
csAutoLoader::csAutoLoader()
{
loading = false;
}
void csAutoLoader::AddJob(const char* name, const char* fname)
{
csAutoLoaderJob job;
job.fname = new char[strlen(fname)];
job.name = new char[strlen(name)];
strcpy(job.fname,fname);
strcpy(job.name,name);
jobs.Push(job);
}
void csAutoLoader::RemoveJob(const char* name)
{
int i;
for(i = 0;i<jobs.GetSize();i++)
{
if(strcmp(jobs.GetAt(i).name, name)==0)
{
csAutoLoaderJob job = jobs.GetAt(i);
delete [] job.fname;
delete [] job.name;
delete [] job.type;
jobs.DeleteIndex(i);
}
}
}
void csAutoLoader::StartLoad(/*iAutoLoaderProgress& progress = internal*/)
{
//current = progress;
loading = true;
csRef<csThread> thread = csThread::Create(new csAutoThreadedLoad);
thread->Start();
}
bool csAutoLoader::Finish()
{
if(!loading)
{
csRef<iLoader> loader;
//TODO: initialize loader
csArray<csAutoLoaderJob>::Iterator it;
it = jobs->GetIterator();
int i = 0;
while(it.HasNext())
{
job = it.Next();
if(job.done)
{
if(loader->Load(&job.data))
jobs->DeleteIndex(i);
}
i++;
}
return true;
}
else return false;
}
In CS\include\imap\csautoloader.h :
Code:
/*
Copyright (C) 2006 by Joshua Warner
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_AUTOLOADER_H__
#define __CS_AUTOLOADER_H__
//class csAutoLoaderProgress;
class csAutoLoader;
//class iAutoLoaderProgress;
class iAutoLoader;
/*class csAutoLoaderProgress : public iAutoLoaderProgress
{
public:
csAutoLoaderProgress(void){SetTotal(100);SetComplete(0);abort = false;finished = false;}
~csAutoLoaderProgress(void){return;}
virtual void Abort(){abort = true;}
virtual void Finalize(){finished = true;}
virtual void Finished(){finished = true;complete = 0;}
virtual bool IsFinished(){return finished;}
virtual bool IsAborted(){return abort;}
virtual float GetCurrent(){return ((float)complete/(float)total);}
virtual int GetTotal(){return total;}
virtual int GetComplete(){return complete;}
virtual void SetComplete(int num){complete = num;}
virtual void SetTotal(int num){total = num;}
virtual void Step(int num = 1){if(total>=complete)complete+=num;else Finished();}
private:
int total;
int complete;
bool finished;
bool abort;
};*/
static struct csAutoLoaderJob
{
const char* name;
const char* fname;
bool done;
csRef<iDataBuffer> data;
};
static class csAutoThreadedLoad : public csRunnable
{
public:
virtual void Run(csAutoLoader* aloader);
};
class csAutoLoader : public iAutoLoader
{
public:
csAutoLoader();
~csAutoLoader();
struct Component : public iComponent
{
SCF_DECLARE_EMBEDDED_IBASE (MyPlugin);
virtual bool Initialize (iObjectRegistry* r)
{ return scfParent->Initialize (r); }
} scfiComponent;
virtual void AddJob(const char* name, const char* fname);
virtual void RemoveJob(const char* name);
virtual void StartLoad(/*iAutoLoaderProgress& progress = internal*/);
virtual void Initialize(iObjectRegistry* r){loader = CS_QUERY_REGISTRY(r, loader);}
virtual bool Finish();
//add custom map loading funtions.
private:
csArray<csAutoLoaderJob> jobs;
//csRef<iAutoLoaderProgress> internal;
//csRef<iAutoLoaderProgress> current;
bool loading;
csRef<iLoader> loader;
friend class csAutoThreadedLoad;
};
#endif // __CS_AUTOLOADER_H__
Copyright (C) 2006 by Joshua Warner
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_AUTOLOADER_H__
#define __CS_AUTOLOADER_H__
//class csAutoLoaderProgress;
class csAutoLoader;
//class iAutoLoaderProgress;
class iAutoLoader;
/*class csAutoLoaderProgress : public iAutoLoaderProgress
{
public:
csAutoLoaderProgress(void){SetTotal(100);SetComplete(0);abort = false;finished = false;}
~csAutoLoaderProgress(void){return;}
virtual void Abort(){abort = true;}
virtual void Finalize(){finished = true;}
virtual void Finished(){finished = true;complete = 0;}
virtual bool IsFinished(){return finished;}
virtual bool IsAborted(){return abort;}
virtual float GetCurrent(){return ((float)complete/(float)total);}
virtual int GetTotal(){return total;}
virtual int GetComplete(){return complete;}
virtual void SetComplete(int num){complete = num;}
virtual void SetTotal(int num){total = num;}
virtual void Step(int num = 1){if(total>=complete)complete+=num;else Finished();}
private:
int total;
int complete;
bool finished;
bool abort;
};*/
static struct csAutoLoaderJob
{
const char* name;
const char* fname;
bool done;
csRef<iDataBuffer> data;
};
static class csAutoThreadedLoad : public csRunnable
{
public:
virtual void Run(csAutoLoader* aloader);
};
class csAutoLoader : public iAutoLoader
{
public:
csAutoLoader();
~csAutoLoader();
struct Component : public iComponent
{
SCF_DECLARE_EMBEDDED_IBASE (MyPlugin);
virtual bool Initialize (iObjectRegistry* r)
{ return scfParent->Initialize (r); }
} scfiComponent;
virtual void AddJob(const char* name, const char* fname);
virtual void RemoveJob(const char* name);
virtual void StartLoad(/*iAutoLoaderProgress& progress = internal*/);
virtual void Initialize(iObjectRegistry* r){loader = CS_QUERY_REGISTRY(r, loader);}
virtual bool Finish();
//add custom map loading funtions.
private:
csArray<csAutoLoaderJob> jobs;
//csRef<iAutoLoaderProgress> internal;
//csRef<iAutoLoaderProgress> current;
bool loading;
csRef<iLoader> loader;
friend class csAutoThreadedLoad;
};
#endif // __CS_AUTOLOADER_H__
Please note that while reading this code, you will probably see many errors in it. I ask only that someone tell me what I am doing wrong with interfacing it with CS.
What I am getting now is errors concerning include statements. Also, it would be helpful if someone could give me some info on the use of the CS plugin define statements, as the documentation seems a little out of date on this issue. (all the plugins that I have looked at the code for use a different method than what is described in the documentation.)
Thanks for voting on the pole - those that did. FYI, the progress handeling code is commented out for debugging purposes. It will be enabled once I get everything else working.





