- finished basic implementation
- removed almost all old stuff - Lux engine uses new FS
This commit is contained in:
parent
c54b5fd502
commit
4443252c2b
26 changed files with 192 additions and 875 deletions
|
@ -93,7 +93,6 @@
|
|||
<ClCompile Include="..\..\src\core\event_manager.cpp" />
|
||||
<ClCompile Include="..\..\src\core\file_system.cpp" />
|
||||
<ClCompile Include="..\..\src\core\file_utils.cpp" />
|
||||
<ClCompile Include="..\..\src\core\ifilesystem.cpp" />
|
||||
<ClCompile Include="..\..\src\core\istream.cpp" />
|
||||
<ClCompile Include="..\..\src\core\jsmn.cpp" />
|
||||
<ClCompile Include="..\..\src\core\json_object.cpp" />
|
||||
|
@ -104,7 +103,6 @@
|
|||
<ClCompile Include="..\..\src\core\memory_file_system.cpp" />
|
||||
<ClCompile Include="..\..\src\core\memory_stream.cpp" />
|
||||
<ClCompile Include="..\..\src\core\quat.cpp" />
|
||||
<ClCompile Include="..\..\src\core\raw_file_stream.cpp" />
|
||||
<ClCompile Include="..\..\src\core\sha1.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
|
@ -125,7 +123,6 @@
|
|||
<ClInclude Include="..\..\src\core\functor.h" />
|
||||
<ClInclude Include="..\..\src\core\idevice.h" />
|
||||
<ClInclude Include="..\..\src\core\ifile.h" />
|
||||
<ClInclude Include="..\..\src\core\ifilesystem.h" />
|
||||
<ClInclude Include="..\..\src\core\ifile_system_defines.h" />
|
||||
<ClInclude Include="..\..\src\core\iserializer.h" />
|
||||
<ClInclude Include="..\..\src\core\lock_free_fifo.h" />
|
||||
|
@ -143,7 +140,6 @@
|
|||
<ClInclude Include="..\..\src\core\memory_file_system.h" />
|
||||
<ClInclude Include="..\..\src\core\memory_stream.h" />
|
||||
<ClInclude Include="..\..\src\core\quat.h" />
|
||||
<ClInclude Include="..\..\src\core\raw_file_stream.h" />
|
||||
<ClInclude Include="..\..\src\core\sha1.h">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
|
|
|
@ -12,19 +12,33 @@
|
|||
<ClCompile Include="..\..\src\core\quat.cpp" />
|
||||
<ClCompile Include="..\..\src\core\sha1.cpp" />
|
||||
<ClCompile Include="..\..\src\core\file_utils.cpp" />
|
||||
<ClCompile Include="..\..\src\core\raw_file_stream.cpp" />
|
||||
<ClCompile Include="..\..\src\core\math_utils.cpp" />
|
||||
<ClCompile Include="..\..\src\core\memory_stream.cpp" />
|
||||
<ClCompile Include="..\..\src\core\ifilesystem.cpp" />
|
||||
<ClCompile Include="..\..\src\core\log.cpp" />
|
||||
<ClCompile Include="..\..\src\core\disk_file_system.cpp" />
|
||||
<ClCompile Include="..\..\src\core\memory_file_system.cpp" />
|
||||
<ClCompile Include="..\..\src\core\file_system.cpp" />
|
||||
<ClCompile Include="..\..\src\core\tcp_file_system.cpp" />
|
||||
<ClCompile Include="..\..\src\core\tcp_acceptor.cpp" />
|
||||
<ClCompile Include="..\..\src\core\tcp_stream.cpp" />
|
||||
<ClCompile Include="..\..\src\core\tcp_connector.cpp" />
|
||||
<ClCompile Include="..\..\src\core\tcp_file_server.cpp" />
|
||||
<ClCompile Include="..\..\src\core\disk_file_system.cpp">
|
||||
<Filter>FS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\memory_file_system.cpp">
|
||||
<Filter>FS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\file_system.cpp">
|
||||
<Filter>FS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\tcp_file_server.cpp">
|
||||
<Filter>FS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\tcp_file_system.cpp">
|
||||
<Filter>FS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\tcp_acceptor.cpp">
|
||||
<Filter>Net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\tcp_connector.cpp">
|
||||
<Filter>Net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\tcp_stream.cpp">
|
||||
<Filter>Net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\memory_stream.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\core\base64.h" />
|
||||
|
@ -43,26 +57,54 @@
|
|||
<ClInclude Include="..\..\src\core\vector.h" />
|
||||
<ClInclude Include="..\..\src\core\lux.h" />
|
||||
<ClInclude Include="..\..\src\core\file_utils.h" />
|
||||
<ClInclude Include="..\..\src\core\raw_file_stream.h" />
|
||||
<ClInclude Include="..\..\src\core\math_utils.h" />
|
||||
<ClInclude Include="..\..\src\core\memory_stream.h" />
|
||||
<ClInclude Include="..\..\src\core\functor.h" />
|
||||
<ClInclude Include="..\..\src\core\ifilesystem.h" />
|
||||
<ClInclude Include="..\..\src\core\iserializer.h" />
|
||||
<ClInclude Include="..\..\src\core\log.h" />
|
||||
<ClInclude Include="..\..\src\core\lock_free_fifo.h" />
|
||||
<ClInclude Include="..\..\src\core\lock_free_queue.h" />
|
||||
<ClInclude Include="..\..\src\core\transaction_queue.h" />
|
||||
<ClInclude Include="..\..\src\core\disk_file_system.h" />
|
||||
<ClInclude Include="..\..\src\core\idevice.h" />
|
||||
<ClInclude Include="..\..\src\core\ifile.h" />
|
||||
<ClInclude Include="..\..\src\core\ifile_system_defines.h" />
|
||||
<ClInclude Include="..\..\src\core\memory_file_system.h" />
|
||||
<ClInclude Include="..\..\src\core\file_system.h" />
|
||||
<ClInclude Include="..\..\src\core\tcp_file_system.h" />
|
||||
<ClInclude Include="..\..\src\core\tcp_acceptor.h" />
|
||||
<ClInclude Include="..\..\src\core\tcp_stream.h" />
|
||||
<ClInclude Include="..\..\src\core\tcp_connector.h" />
|
||||
<ClInclude Include="..\..\src\core\tcp_file_server.h" />
|
||||
<ClInclude Include="..\..\src\core\disk_file_system.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\ifile_system_defines.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\memory_file_system.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\file_system.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\tcp_file_server.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\tcp_file_system.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\tcp_acceptor.h">
|
||||
<Filter>Net</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\tcp_connector.h">
|
||||
<Filter>Net</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\tcp_stream.h">
|
||||
<Filter>Net</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\ifile.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\idevice.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\memory_stream.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="FS">
|
||||
<UniqueIdentifier>{44dff5e3-a667-4449-ae33-ca7c1b548fe3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Net">
|
||||
<UniqueIdentifier>{711c9117-702c-45a0-b264-2ca658a044b2}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -95,7 +95,6 @@
|
|||
<ClInclude Include="..\..\src\platform\socket.h" />
|
||||
<ClInclude Include="..\..\src\platform\spin_mutex.h" />
|
||||
<ClInclude Include="..\..\src\platform\task.h" />
|
||||
<ClInclude Include="..\..\src\platform\tcp_filesystem.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\platform\os_file.cpp" />
|
||||
|
@ -107,7 +106,6 @@
|
|||
<ClCompile Include="..\..\src\platform\pc\socket.cpp" />
|
||||
<ClCompile Include="..\..\src\platform\pc\spin_mutex.cpp" />
|
||||
<ClCompile Include="..\..\src\platform\pc\task.cpp" />
|
||||
<ClCompile Include="..\..\src\platform\pc\tcp_filesystem.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
<ClInclude Include="..\..\src\platform\socket.h" />
|
||||
<ClInclude Include="..\..\src\platform\task.h" />
|
||||
<ClInclude Include="..\..\src\platform\input_system.h" />
|
||||
<ClInclude Include="..\..\src\platform\tcp_filesystem.h" />
|
||||
<ClInclude Include="..\..\src\platform\event.h" />
|
||||
<ClInclude Include="..\..\src\platform\mutex.h" />
|
||||
<ClInclude Include="..\..\src\platform\semaphore.h" />
|
||||
|
@ -20,7 +19,6 @@
|
|||
<ClCompile Include="..\..\src\platform\pc\socket.cpp" />
|
||||
<ClCompile Include="..\..\src\platform\pc\spin_mutex.cpp" />
|
||||
<ClCompile Include="..\..\src\platform\pc\task.cpp" />
|
||||
<ClCompile Include="..\..\src\platform\pc\tcp_filesystem.cpp" />
|
||||
<ClCompile Include="..\..\src\platform\pc\atomic.cpp" />
|
||||
<ClCompile Include="..\..\src\platform\os_file.cpp" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Lux
|
|||
class DiskFile : public IFile
|
||||
{
|
||||
public:
|
||||
DiskFile(IFile* parent) {}
|
||||
DiskFile() {}
|
||||
virtual ~DiskFile() {}
|
||||
|
||||
virtual bool open(const char* path, Mode mode) LUX_OVERRIDE
|
||||
|
@ -60,9 +60,9 @@ namespace Lux
|
|||
OsFile m_file;
|
||||
};
|
||||
|
||||
IFile* DiskFileSystem::create(IFile* parent)
|
||||
IFile* DiskFileSystem::create(IFile* child)
|
||||
{
|
||||
return new DiskFile(parent);
|
||||
return new DiskFile();
|
||||
}
|
||||
} // namespace FS
|
||||
} // ~namespace Lux
|
|
@ -44,7 +44,7 @@ namespace Lux
|
|||
|
||||
tr->data.m_result = tr->data.m_user_data != NULL
|
||||
? tr->data.m_file->open(tr->data.m_path, tr->data.m_mode)
|
||||
: true, tr->data.m_file->close();
|
||||
: (tr->data.m_file->close(), true);
|
||||
tr->setCompleted();
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
#include "ifilesystem.h"
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
IFileSystem::~IFileSystem() {}
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include "core/lux.h"
|
||||
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
class LUX_CORE_API IFileSystem
|
||||
{
|
||||
public:
|
||||
typedef int Handle;
|
||||
typedef void (*ReadCallback)(void* user_data, char* file_data, int length, bool success);
|
||||
|
||||
public:
|
||||
virtual ~IFileSystem();
|
||||
|
||||
virtual Handle openFile(const char* path, ReadCallback callback, void* user_data) = 0;
|
||||
};
|
||||
|
||||
} // ~namespace Lux
|
|
@ -6,13 +6,13 @@ namespace Lux
|
|||
{
|
||||
|
||||
|
||||
JsonSerializer::JsonSerializer(IStream& stream, AccessMode access_mode)
|
||||
: m_stream(stream)
|
||||
JsonSerializer::JsonSerializer(FS::IFile& file, AccessMode access_mode)
|
||||
: m_file(file)
|
||||
, m_access_mode(access_mode)
|
||||
{
|
||||
if(m_access_mode == READ)
|
||||
{
|
||||
m_stream.read(&m_buffer, 1);
|
||||
m_file.read(&m_buffer, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ void JsonSerializer::serialize(const char* label, unsigned int value)
|
|||
writeBlockComma();
|
||||
char tmp[20];
|
||||
sprintf_s(tmp, "\"%s\" : %u", label, value);
|
||||
m_stream.write(tmp);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ void JsonSerializer::serialize(const char* label, float value)
|
|||
writeBlockComma();
|
||||
char tmp[100];
|
||||
sprintf_s(tmp, "\"%s\" : %f", label, value);
|
||||
m_stream.write(tmp);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ void JsonSerializer::serialize(const char* label, int value)
|
|||
writeBlockComma();
|
||||
char tmp[100];
|
||||
sprintf_s(tmp, "\"%s\" : %d", label, value);
|
||||
m_stream.write(tmp);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -52,9 +52,9 @@ void JsonSerializer::serialize(const char* label, const char* value)
|
|||
{
|
||||
writeBlockComma();
|
||||
writeString(label);
|
||||
m_stream.write(" : \"");
|
||||
m_stream.write(value);
|
||||
m_stream.write("\"");
|
||||
m_file.write(" : \"", 4);
|
||||
m_file.write(value, strlen(value));
|
||||
m_file.write("\"", 1);
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ void JsonSerializer::serialize(const char* label, bool value)
|
|||
{
|
||||
writeBlockComma();
|
||||
writeString(label);
|
||||
m_stream.write(value ? " : true" : " : false");
|
||||
m_file.write(value ? " : true" : " : false", value ? 7 : 8);
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -72,14 +72,14 @@ void JsonSerializer::beginArray(const char* label)
|
|||
{
|
||||
writeBlockComma();
|
||||
writeString(label);
|
||||
m_stream.write(" : [");
|
||||
m_file.write(" : [", 4);
|
||||
m_is_first_in_block = true;
|
||||
}
|
||||
|
||||
|
||||
void JsonSerializer::endArray()
|
||||
{
|
||||
m_stream.write("]");
|
||||
m_file.write("]", 1);
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ void JsonSerializer::serializeArrayItem(unsigned int value)
|
|||
writeBlockComma();
|
||||
char tmp[20];
|
||||
sprintf_s(tmp, "%u", value);
|
||||
m_stream.write(tmp);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ void JsonSerializer::serializeArrayItem(int value)
|
|||
writeBlockComma();
|
||||
char tmp[20];
|
||||
sprintf_s(tmp, "%d", value);
|
||||
m_stream.write(tmp);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ void JsonSerializer::serializeArrayItem(float value)
|
|||
writeBlockComma();
|
||||
char tmp[20];
|
||||
sprintf_s(tmp, "%f", value);
|
||||
m_stream.write(tmp);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ void JsonSerializer::serializeArrayItem(float value)
|
|||
void JsonSerializer::serializeArrayItem(bool value)
|
||||
{
|
||||
writeBlockComma();
|
||||
m_stream.write(value ? "true" : "false");
|
||||
m_file.write(value ? "true" : "false", value ? 4 : 5);
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
||||
|
@ -149,13 +149,15 @@ void JsonSerializer::deserialize(const char* label, float& value)
|
|||
{
|
||||
tmp[i] = c;
|
||||
++i;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
while((c >= '0' && c <= '9') || c == '.')
|
||||
|
||||
bool ret = true;
|
||||
while(ret && ((c >= '0' && c <= '9') || c == '.'))
|
||||
{
|
||||
tmp[i] = c;
|
||||
++i;
|
||||
m_stream.read(&c, 1);
|
||||
ret = m_file.read(&c, 1);
|
||||
}
|
||||
tmp[i] = 0;
|
||||
sscanf_s(tmp, "%f", &value);
|
||||
|
@ -170,10 +172,11 @@ void JsonSerializer::deserialize(const char* label, unsigned int& value)
|
|||
|
||||
unsigned char c = m_buffer;
|
||||
value = 0;
|
||||
while(c >= '0' && c <= '9')
|
||||
bool ret = true;
|
||||
while(ret && (c >= '0' && c <= '9'))
|
||||
{
|
||||
value += c - '0';
|
||||
m_stream.read(&c, 1);
|
||||
ret = m_file.read(&c, 1);
|
||||
}
|
||||
m_buffer = c;
|
||||
skipControl();
|
||||
|
@ -190,13 +193,14 @@ void JsonSerializer::deserialize(const char* label, int& value)
|
|||
if(c == '-')
|
||||
{
|
||||
sign = -1;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
while(c >= '0' && c <= '9')
|
||||
bool ret = true;
|
||||
while(ret && (c >= '0' && c <= '9'))
|
||||
{
|
||||
value *= 10;
|
||||
value += c - '0';
|
||||
m_stream.read(&c, 1);
|
||||
ret = m_file.read(&c, 1);
|
||||
}
|
||||
value *= sign;
|
||||
m_buffer = c;
|
||||
|
@ -210,15 +214,15 @@ void JsonSerializer::deserialize(const char* label, char* value)
|
|||
|
||||
int index = 0;
|
||||
unsigned char c;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
while(c != '\"')
|
||||
{
|
||||
value[index] = c;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
++index;
|
||||
}
|
||||
value[index] = 0;
|
||||
m_stream.read(&m_buffer, 1);
|
||||
m_file.read(&m_buffer, 1);
|
||||
skipControl();
|
||||
}
|
||||
|
||||
|
@ -233,16 +237,16 @@ void JsonSerializer::deserializeArrayBegin(const char* label)
|
|||
void JsonSerializer::deserializeArrayItem(char* value)
|
||||
{
|
||||
unsigned char c;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
char* out = value;
|
||||
while(c != '"')
|
||||
{
|
||||
*out = c;
|
||||
++out;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
*out = 0;
|
||||
m_stream.read(&m_buffer, 1);
|
||||
m_file.read(&m_buffer, 1);
|
||||
skipControl();
|
||||
}
|
||||
|
||||
|
@ -250,7 +254,7 @@ void JsonSerializer::deserializeArrayItem(char* value)
|
|||
void JsonSerializer::deserializeArrayItem(string& value)
|
||||
{
|
||||
unsigned char c;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
char tmp[100];
|
||||
char* out = tmp;
|
||||
while(c != '"')
|
||||
|
@ -263,11 +267,11 @@ void JsonSerializer::deserializeArrayItem(string& value)
|
|||
value += tmp;
|
||||
out = tmp;
|
||||
}
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
*out = 0;
|
||||
value = tmp;
|
||||
m_stream.read(&m_buffer, 1);
|
||||
m_file.read(&m_buffer, 1);
|
||||
skipControl();
|
||||
}
|
||||
|
||||
|
@ -280,7 +284,7 @@ void JsonSerializer::deserializeArrayItem(unsigned int& value)
|
|||
{
|
||||
value *= 10;
|
||||
value += c - '0';
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
m_buffer = c;
|
||||
skipControl();
|
||||
|
@ -295,13 +299,13 @@ void JsonSerializer::deserializeArrayItem(int& value)
|
|||
if(c == '-')
|
||||
{
|
||||
sign = -1;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
while(c >= '0' && c <= '9')
|
||||
{
|
||||
value *= 10;
|
||||
value += c - '0';
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
value *= sign;
|
||||
m_buffer = c;
|
||||
|
@ -319,13 +323,13 @@ void JsonSerializer::deserializeArrayItem(float& value)
|
|||
{
|
||||
tmp[i] = c;
|
||||
++i;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
while((c >= '0' && c <= '9') || c == '.')
|
||||
{
|
||||
tmp[i] = c;
|
||||
++i;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
tmp[i] = 0;
|
||||
sscanf_s(tmp, "%f", &value);
|
||||
|
@ -344,7 +348,7 @@ void JsonSerializer::deserializeArrayItem(bool& value)
|
|||
{
|
||||
tmp[i] = c;
|
||||
++i;
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
}
|
||||
tmp[i] = 0;
|
||||
value = strcmp("true", tmp) == 0;
|
||||
|
@ -359,12 +363,12 @@ void JsonSerializer::deserialize(const char* label, bool& value)
|
|||
unsigned char tmp[5];
|
||||
if(m_buffer == 't')
|
||||
{
|
||||
m_stream.read(tmp, 3);
|
||||
m_file.read(tmp, 3);
|
||||
m_buffer = tmp[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_stream.read(tmp, 4);
|
||||
m_file.read(tmp, 4);
|
||||
m_buffer = tmp[3];
|
||||
}
|
||||
skipControl();
|
||||
|
@ -379,7 +383,7 @@ void JsonSerializer::deserializeLabel(const char* label)
|
|||
char* to = tmp;
|
||||
do
|
||||
{
|
||||
m_stream.read(&c, 1);
|
||||
m_file.read(&c, 1);
|
||||
*to = c;
|
||||
++to;
|
||||
}
|
||||
|
@ -387,9 +391,7 @@ void JsonSerializer::deserializeLabel(const char* label)
|
|||
--to;
|
||||
*to = 0;
|
||||
ASSERT(strcmp(label, tmp) == 0);
|
||||
m_stream.read(&m_buffer, 1);
|
||||
m_file.read(&m_buffer, 1);
|
||||
skipControl();
|
||||
}
|
||||
|
||||
|
||||
} // ~namespace lux
|
||||
} // ~namespace lux
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
#include "core/iserializer.h"
|
||||
#include "core/istream.h"
|
||||
#include "core/ifile.h"
|
||||
#include "core/string.h"
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace Lux
|
|||
};
|
||||
|
||||
public:
|
||||
JsonSerializer(IStream& stream, AccessMode access_mode);
|
||||
JsonSerializer(FS::IFile& file, AccessMode access_mode);
|
||||
|
||||
// serialize
|
||||
virtual void serialize(const char* label, uint32_t value) LUX_OVERRIDE;
|
||||
|
@ -60,16 +60,16 @@ namespace Lux
|
|||
|
||||
inline void writeString(const char* str)
|
||||
{
|
||||
m_stream.write("\"", 1);
|
||||
m_stream.write(str);
|
||||
m_stream.write("\"", 1);
|
||||
m_file.write("\"", 1);
|
||||
m_file.write(str, strlen(str));
|
||||
m_file.write("\"", 1);
|
||||
}
|
||||
|
||||
inline void writeBlockComma()
|
||||
{
|
||||
if(!m_is_first_in_block)
|
||||
{
|
||||
m_stream.write(",\n");
|
||||
m_file.write(",\n", 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ namespace Lux
|
|||
unsigned char c = m_buffer;
|
||||
while(c == ','|| c == ' ' || c == '\t' || c == '{' || c == '[' || c == '\n' || c == '\r' || c == ':' || c == ']' || c == '}')
|
||||
{
|
||||
if(!m_stream.read(&c, 1))
|
||||
if(!m_file.read(&c, 1))
|
||||
return;
|
||||
}
|
||||
m_buffer = c;
|
||||
|
@ -89,7 +89,7 @@ namespace Lux
|
|||
unsigned char m_buffer;
|
||||
bool m_is_first_in_block;
|
||||
unsigned char* m_data;
|
||||
IStream& m_stream;
|
||||
FS::IFile& m_file;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace Lux
|
|||
virtual bool read(void* buffer, size_t size) LUX_OVERRIDE
|
||||
{
|
||||
size_t amount = m_pos + size < m_size ? size : m_size - m_pos;
|
||||
memcpy(m_buffer + m_pos, buffer, amount);
|
||||
memcpy(buffer, m_buffer + m_pos, amount);
|
||||
m_pos += amount;
|
||||
return amount == size;
|
||||
}
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
#include "raw_file_stream.h"
|
||||
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
|
||||
RawFileStream::RawFileStream()
|
||||
{
|
||||
m_fp = 0;
|
||||
}
|
||||
|
||||
|
||||
RawFileStream::~RawFileStream()
|
||||
{
|
||||
ASSERT(m_fp == 0);
|
||||
}
|
||||
|
||||
|
||||
bool RawFileStream::create(const char* path, Mode mode)
|
||||
{
|
||||
const char* mode_str = mode == Mode::READ ? "r" : "w";
|
||||
m_fp = 0;
|
||||
fopen_s(&m_fp, path, mode_str);
|
||||
return m_fp != 0;
|
||||
}
|
||||
|
||||
|
||||
void RawFileStream::destroy()
|
||||
{
|
||||
fclose(m_fp);
|
||||
m_fp = 0;
|
||||
}
|
||||
|
||||
|
||||
void RawFileStream::write(const void* data, size_t size)
|
||||
{
|
||||
fwrite(data, size, 1, m_fp);
|
||||
}
|
||||
|
||||
|
||||
bool RawFileStream::read(void* data, size_t size)
|
||||
{
|
||||
size_t read = fread(data, size, 1, m_fp);
|
||||
if(read == 0)
|
||||
{
|
||||
for(size_t i = 0; i < size; ++i)
|
||||
((unsigned char*)data)[i] = 0;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // !namespace Lux
|
|
@ -1,43 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include "core/lux.h"
|
||||
#include "core/istream.h"
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
|
||||
class LUX_CORE_API RawFileStream : public IStream
|
||||
{
|
||||
public:
|
||||
struct Mode
|
||||
{
|
||||
enum Value
|
||||
{
|
||||
READ,
|
||||
WRITE
|
||||
};
|
||||
Mode(Value _value) : value(_value) {}
|
||||
operator Value() { return value; }
|
||||
Value value;
|
||||
};
|
||||
|
||||
public:
|
||||
RawFileStream();
|
||||
~RawFileStream();
|
||||
|
||||
bool create(const char* path, Mode mode);
|
||||
void destroy();
|
||||
|
||||
virtual void write(const void* data, size_t size) LUX_OVERRIDE;
|
||||
virtual bool read(void* data, size_t size) LUX_OVERRIDE;
|
||||
|
||||
private:
|
||||
FILE* m_fp;
|
||||
};
|
||||
|
||||
|
||||
} // !namespace Lux
|
|
@ -1,6 +1,6 @@
|
|||
#include "core/tcp_file_server.h"
|
||||
|
||||
#include "core/tcp_connector.h"
|
||||
#include "core/tcp_acceptor.h"
|
||||
#include "core/tcp_file_system.h"
|
||||
#include "core/tcp_stream.h"
|
||||
#include "platform/task.h"
|
||||
|
@ -18,11 +18,14 @@ namespace Lux
|
|||
|
||||
int task()
|
||||
{
|
||||
Net::TCPStream* stream = m_connector.connect("127.0.0.1", 10001);
|
||||
char buffer[1024];
|
||||
bool quit = false;
|
||||
|
||||
m_acceptor.start("127.0.0.1", 10001);
|
||||
Net::TCPStream* stream = m_acceptor.accept();
|
||||
|
||||
OsFile* file = new OsFile();
|
||||
while(true)
|
||||
while(!quit)
|
||||
{
|
||||
int32_t op = 0;
|
||||
stream->read(op);
|
||||
|
@ -67,8 +70,8 @@ namespace Lux
|
|||
while(size > 0)
|
||||
{
|
||||
int32_t read = size > 1024 ? 1024 : size;
|
||||
stream->read(buffer, read);
|
||||
file->write(buffer, read);
|
||||
stream->read((void*)buffer, read);
|
||||
file->write((void*)buffer, read);
|
||||
size -= read;
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +99,14 @@ namespace Lux
|
|||
stream->write(pos);
|
||||
}
|
||||
break;
|
||||
case TCPCommand::Disconnect:
|
||||
{
|
||||
quit = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -104,7 +115,7 @@ namespace Lux
|
|||
void stop() {} // TODO: implement stop
|
||||
|
||||
private:
|
||||
Net::TCPConnector m_connector;
|
||||
Net::TCPAcceptor m_acceptor;
|
||||
};
|
||||
|
||||
struct TCPFileServerImpl
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "core/ifile.h"
|
||||
#include "core/ifile_system_defines.h"
|
||||
#include "core/file_system.h"
|
||||
#include "core/tcp_acceptor.h"
|
||||
#include "core/tcp_connector.h"
|
||||
#include "core/tcp_stream.h"
|
||||
#include "platform/task.h"
|
||||
|
||||
|
@ -19,7 +19,6 @@ namespace Lux
|
|||
|
||||
virtual bool open(const char* path, Mode mode) LUX_OVERRIDE
|
||||
{
|
||||
while(!m_fs->isInitialized());
|
||||
int32_t op = TCPCommand::OpenFile;
|
||||
int32_t ret = 0;
|
||||
|
||||
|
@ -101,32 +100,10 @@ namespace Lux
|
|||
|
||||
struct TCPImpl
|
||||
{
|
||||
Net::TCPConnector m_connector;
|
||||
Net::TCPStream* m_stream;
|
||||
};
|
||||
|
||||
class TCPFileSystemTask : public MT::Task
|
||||
{
|
||||
public:
|
||||
TCPFileSystemTask(TCPImpl* impl) : m_impl(impl) {}
|
||||
~TCPFileSystemTask() {};
|
||||
|
||||
int task()
|
||||
{
|
||||
m_impl->m_stream = m_acceptor.accept();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void start(const char* ip, uint16_t port)
|
||||
{
|
||||
m_acceptor.start(ip, port);
|
||||
}
|
||||
|
||||
private:
|
||||
TCPImpl* m_impl;
|
||||
Net::TCPAcceptor m_acceptor;
|
||||
};
|
||||
|
||||
IFile* TCPFileSystem::create(IFile* parent)
|
||||
{
|
||||
return new TCPFile(parent, m_impl->m_stream);
|
||||
|
@ -135,28 +112,13 @@ namespace Lux
|
|||
void TCPFileSystem::start(const char* ip, uint16_t port)
|
||||
{
|
||||
m_impl = new TCPImpl;
|
||||
m_task = new TCPFileSystemTask(m_impl);
|
||||
m_task->start(ip, port);
|
||||
m_task->create("TCP File System");
|
||||
m_task->run();
|
||||
m_impl->m_stream = m_impl->m_connector.connect(ip, port);
|
||||
}
|
||||
|
||||
void TCPFileSystem::stop()
|
||||
{
|
||||
// todo: destroy task after it's finished
|
||||
m_task->destroy();
|
||||
delete m_task;
|
||||
m_impl->m_stream->write(TCPCommand::Disconnect);
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
bool TCPFileSystem::isInitialized() const
|
||||
{
|
||||
return m_task->isFinished();
|
||||
}
|
||||
|
||||
Net::TCPStream* TCPFileSystem::getStream()
|
||||
{
|
||||
return m_impl->m_stream;
|
||||
}
|
||||
} // namespace FS
|
||||
} // ~namespace Lux
|
|
@ -28,6 +28,7 @@ namespace Lux
|
|||
Seek,
|
||||
Pos,
|
||||
Exit,
|
||||
Disconnect,
|
||||
};
|
||||
|
||||
TCPCommand() : value(0) {}
|
||||
|
@ -46,12 +47,8 @@ namespace Lux
|
|||
void start(const char* ip, uint16_t port);
|
||||
void stop();
|
||||
|
||||
bool isInitialized() const;
|
||||
Net::TCPStream* getStream();
|
||||
|
||||
private:
|
||||
TCPFileSystemTask* m_task;
|
||||
TCPImpl* m_impl;
|
||||
};
|
||||
} // ~namespace FS
|
||||
} // ~namespace Lux
|
||||
} // ~namespace Lux
|
||||
|
|
|
@ -11,9 +11,8 @@
|
|||
#include "core/log.h"
|
||||
#include "core/map.h"
|
||||
#include "core/matrix.h"
|
||||
#include "core/memory_stream.h"
|
||||
#include "core/crc32.h"
|
||||
#include "core/raw_file_stream.h"
|
||||
#include "core/memory_stream.h"
|
||||
#include "core/vector.h"
|
||||
#include "editor/editor_icon.h"
|
||||
#include "editor/gizmo.h"
|
||||
|
@ -26,7 +25,6 @@
|
|||
#include "platform/mutex.h"
|
||||
#include "platform/socket.h"
|
||||
#include "platform/task.h"
|
||||
#include "platform/tcp_filesystem.h"
|
||||
#include "script\script_system.h"
|
||||
#include "universe/component_event.h"
|
||||
#include "universe/entity_destroyed_event.h"
|
||||
|
@ -147,8 +145,8 @@ struct EditorServerImpl
|
|||
void logMessage(int32_t type, const char* system, const char* msg);
|
||||
Entity& getSelectedEntity() { return m_selected_entity; }
|
||||
bool isGameMode() const { return m_is_game_mode; }
|
||||
void save(IStream& stream);
|
||||
void load(IStream& stream);
|
||||
void save(FS::IFile& file);
|
||||
void load(FS::IFile& file);
|
||||
void onMessage(void* msgptr, int size);
|
||||
|
||||
const PropertyDescriptor& getPropertyDescriptor(uint32_t type, const char* name);
|
||||
|
@ -180,7 +178,7 @@ struct EditorServerImpl
|
|||
bool m_is_game_mode;
|
||||
Quat m_camera_rot;
|
||||
Vec3 m_camera_pos;
|
||||
MemoryStream m_game_mode_stream;
|
||||
// MemoryStream m_game_mode_stream;
|
||||
MessageTask* m_message_task;
|
||||
Engine m_engine;
|
||||
EditorServer* m_owner;
|
||||
|
@ -360,16 +358,15 @@ void EditorServerImpl::onPointerUp(int x, int y, MouseButton::Value button)
|
|||
void EditorServerImpl::save(const char path[])
|
||||
{
|
||||
g_log_info.log("editor server", "saving universe %s...", path);
|
||||
RawFileStream stream;
|
||||
stream.create(path, RawFileStream::Mode::WRITE);
|
||||
save(stream);
|
||||
stream.destroy();
|
||||
FS::IFile* file = m_engine.getFileSystem().open("tcp", path, FS::Mode::OPEN_OR_CREATE | FS::Mode::WRITE);
|
||||
save(*file);
|
||||
m_engine.getFileSystem().close(file);
|
||||
}
|
||||
|
||||
|
||||
void EditorServerImpl::save(IStream& stream)
|
||||
void EditorServerImpl::save(FS::IFile& file)
|
||||
{
|
||||
JsonSerializer serializer(stream, JsonSerializer::WRITE);
|
||||
JsonSerializer serializer(file, JsonSerializer::WRITE);
|
||||
m_engine.serialize(serializer);
|
||||
serializer.serialize("cam_pos_x", m_camera_pos.x);
|
||||
serializer.serialize("cam_pos_y", m_camera_pos.y);
|
||||
|
@ -402,7 +399,7 @@ void EditorServerImpl::addEntity()
|
|||
int MessageTask::task()
|
||||
{
|
||||
bool finished = false;
|
||||
m_socket.create(NULL, 10002);
|
||||
m_socket.create("127.0.0.1", 10002);
|
||||
m_work_socket = m_socket.accept();
|
||||
vector<uint8_t> data;
|
||||
data.resize(5);
|
||||
|
@ -432,8 +429,8 @@ void EditorServerImpl::toggleGameMode()
|
|||
}
|
||||
else
|
||||
{
|
||||
m_game_mode_stream.clearBuffer();
|
||||
save(m_game_mode_stream);
|
||||
// m_game_mode_stream.clearBuffer();
|
||||
// save(m_game_mode_stream);
|
||||
m_engine.getScriptSystem().start();
|
||||
m_is_game_mode = true;
|
||||
}
|
||||
|
@ -448,8 +445,8 @@ void EditorServerImpl::stopGameMode()
|
|||
m_camera_rot.toMatrix(mtx);
|
||||
mtx.setTranslation(m_camera_pos);
|
||||
m_engine.getRenderer().setCameraMatrix(mtx);
|
||||
m_game_mode_stream.rewindForRead();
|
||||
load(m_game_mode_stream);
|
||||
// m_game_mode_stream.rewindForRead();
|
||||
// load(m_game_mode_stream);
|
||||
}
|
||||
|
||||
|
||||
|
@ -611,14 +608,14 @@ void EditorServerImpl::removeComponent(uint32_t type_crc)
|
|||
}
|
||||
|
||||
|
||||
void loadMap(void* user_data, char* file_data, int length, bool success)
|
||||
void loadMap(FS::IFile* file, bool success, void* user_data)
|
||||
{
|
||||
ASSERT(success);
|
||||
if(success)
|
||||
{
|
||||
MemoryStream stream;
|
||||
stream.create(file_data, length);
|
||||
static_cast<EditorServerImpl*>(user_data)->load(stream);
|
||||
static_cast<EditorServerImpl*>(user_data)->load(*file);
|
||||
//TODO: close
|
||||
//file->close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -626,7 +623,7 @@ void loadMap(void* user_data, char* file_data, int length, bool success)
|
|||
void EditorServerImpl::load(const char path[])
|
||||
{
|
||||
g_log_info.log("editor server", "loading universe %s...", path);
|
||||
m_engine.getFileSystem().open("memory:tcp", path, FS::Mode::OPEN | FS::Mode::READ);
|
||||
m_engine.getFileSystem().openAsync("memory:tcp", path, FS::Mode::OPEN | FS::Mode::READ, &loadMap, this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -638,13 +635,13 @@ void EditorServerImpl::newUniverse()
|
|||
}
|
||||
|
||||
|
||||
void EditorServerImpl::load(IStream& stream)
|
||||
void EditorServerImpl::load(FS::IFile& file)
|
||||
{
|
||||
g_log_info.log("editor server", "parsing universe...");
|
||||
int selected_idx = m_selected_entity.index;
|
||||
destroyUniverse();
|
||||
createUniverse(false, "");
|
||||
JsonSerializer serializer(stream, JsonSerializer::READ);
|
||||
JsonSerializer serializer(file, JsonSerializer::READ);
|
||||
|
||||
m_engine.deserialize(serializer);
|
||||
serializer.deserialize("cam_pos_x", m_camera_pos.x);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "engine/plugin_manager.h"
|
||||
#include "graphics/renderer.h"
|
||||
#include "platform/input_system.h"
|
||||
#include "platform/tcp_filesystem.h"
|
||||
#include "script/script_system.h"
|
||||
|
||||
#include "core/file_system.h"
|
||||
|
|
|
@ -4,9 +4,12 @@
|
|||
#include "cooking/PxCooking.h"
|
||||
#include "core/crc32.h"
|
||||
#include "core/event_manager.h"
|
||||
#include "core/file_system.h"
|
||||
#include "core/ifile.h"
|
||||
#include "core/iserializer.h"
|
||||
#include "core/json_object.h"
|
||||
#include "core/matrix.h"
|
||||
#include "engine/engine.h"
|
||||
#include "universe/component_event.h"
|
||||
#include "universe/entity_moved_event.h"
|
||||
#include "physics/physics_system.h"
|
||||
|
@ -33,6 +36,7 @@ struct PhysicsSceneImpl
|
|||
};
|
||||
|
||||
Universe* m_universe;
|
||||
Engine* m_engine;
|
||||
physx::PxScene* m_scene;
|
||||
PhysicsSystem* m_system;
|
||||
physx::PxMaterial* m_default_material;
|
||||
|
@ -268,9 +272,9 @@ void PhysicsScene::setShapeSource(Component cmp, const string& str)
|
|||
{
|
||||
return;
|
||||
}
|
||||
FILE* fp;
|
||||
fopen_s(&fp, str.c_str(), "r");
|
||||
if(fp)
|
||||
|
||||
FS::IFile* file = m_impl->m_engine->getFileSystem().open("disk", str.c_str(), FS::Mode::OPEN | FS::Mode::READ);
|
||||
if(file)
|
||||
{
|
||||
physx::PxTransform transform;
|
||||
Matrix mtx;
|
||||
|
@ -282,11 +286,10 @@ void PhysicsScene::setShapeSource(Component cmp, const string& str)
|
|||
physx::PxConvexMeshGeometry convex_geom;
|
||||
physx::PxTriangleMeshGeometry trimesh_geom;
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
long size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
long size = file->size();
|
||||
char* buffer = new char[size];
|
||||
fread(buffer, size, 1, fp);
|
||||
file->read(buffer, size);
|
||||
|
||||
jsmn_parser parser;
|
||||
jsmn_init(&parser);
|
||||
jsmntok_t tokens[255];
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include "core/lux.h"
|
||||
#include "core/file_system.h"
|
||||
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
struct NativeFileSystemImpl;
|
||||
|
||||
|
||||
class LUX_PLATFORM_API NativeFileSystem : public FileSystem
|
||||
{
|
||||
public:
|
||||
bool create();
|
||||
void destroy();
|
||||
|
||||
virtual void open(const char* filename, OnFinished callback, void* data) LUX_OVERRIDE;
|
||||
|
||||
private:
|
||||
NativeFileSystemImpl* m_impl;
|
||||
};
|
||||
|
||||
|
||||
} // ~namespace Lux
|
|
@ -1,95 +0,0 @@
|
|||
#include "native_file_system.h"
|
||||
#include "task.h"
|
||||
#include "core/vector.h"
|
||||
#include <cstdio>
|
||||
#include "core/string.h"
|
||||
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
|
||||
class FileSystemTask : public Task
|
||||
{
|
||||
public:
|
||||
virtual int task() LUX_OVERRIDE;
|
||||
|
||||
NativeFileSystemImpl* fs;
|
||||
};
|
||||
|
||||
|
||||
struct NativeFileSystemImpl
|
||||
{
|
||||
struct Info
|
||||
{
|
||||
FileSystem::OnFinished on_finished;
|
||||
void* data;
|
||||
string path;
|
||||
};
|
||||
|
||||
vector<Info> infos;
|
||||
FileSystemTask task;
|
||||
};
|
||||
|
||||
|
||||
int FileSystemTask::task()
|
||||
{
|
||||
bool finished = false;
|
||||
while(!finished)
|
||||
{
|
||||
if(!fs->infos.empty())
|
||||
{
|
||||
NativeFileSystemImpl::Info& h = fs->infos.back();
|
||||
|
||||
FILE* fp = fopen(h.path.c_str(), "r");
|
||||
if(fp)
|
||||
{
|
||||
fseek(fp, 0, SEEK_END);
|
||||
size_t size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
void* data = new char[size];
|
||||
fread(h.data, 1, size, fp);
|
||||
h.on_finished(h.path.c_str(), h.data, data, size, FileSystem::SUCCESS);
|
||||
delete[] data;
|
||||
}
|
||||
else
|
||||
{
|
||||
h.on_finished(h.path.c_str(), h.data, 0, 0, FileSystem::FAIL);
|
||||
}
|
||||
|
||||
fs->infos.pop_back();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool NativeFileSystem::create()
|
||||
{
|
||||
m_impl = new NativeFileSystemImpl();
|
||||
bool success = m_impl->task.create();
|
||||
m_impl->task.fs = m_impl;
|
||||
success = success && m_impl->task.run();
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
void NativeFileSystem::destroy()
|
||||
{
|
||||
m_impl->task.destroy();
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
|
||||
void NativeFileSystem::open(const char* filename, OnFinished callback, void* data)
|
||||
{
|
||||
NativeFileSystemImpl::Info& info = m_impl->infos.push_back_empty();
|
||||
info.on_finished = callback;
|
||||
info.data = data;
|
||||
info.path = filename;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // ~namespace Lux
|
|
@ -1,93 +0,0 @@
|
|||
#include "tcp_filesystem.h"
|
||||
#include "task.h"
|
||||
#include "core/vector.h"
|
||||
#include "core/string.h"
|
||||
#include "platform/mutex.h"
|
||||
#include <cstdio>
|
||||
#include "socket.h"
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
struct TCPFileSystemTask : public Task
|
||||
{
|
||||
virtual int task() LUX_OVERRIDE;
|
||||
void stop();
|
||||
void handleMessage(char* buffer, int size);
|
||||
|
||||
bool finished;
|
||||
Mutex mutex;
|
||||
struct TCPFileSystemImpl* fs;
|
||||
Socket socket;
|
||||
Socket* work_socket;
|
||||
};
|
||||
|
||||
|
||||
struct TCPFileSystemImpl
|
||||
{
|
||||
struct FileItem
|
||||
{
|
||||
enum Status
|
||||
{
|
||||
LOADING,
|
||||
SUCCESS,
|
||||
FAIL
|
||||
};
|
||||
string path;
|
||||
IFileSystem::ReadCallback callback;
|
||||
void* user_data;
|
||||
char* file_data;
|
||||
int file_length;
|
||||
int uid;
|
||||
Status status;
|
||||
};
|
||||
|
||||
TCPFileSystemTask* task;
|
||||
vector<FileItem*> queue;
|
||||
vector<FileItem*> loaded;
|
||||
vector<FileItem*> in_progress;
|
||||
int last_uid;
|
||||
};
|
||||
|
||||
|
||||
int TCPFileSystemTask::task()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TCPFileSystemTask::handleMessage(char* buffer, int size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TCPFileSystem::processLoaded()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TCPFileSystemTask::stop()
|
||||
{
|
||||
finished = true;
|
||||
}
|
||||
|
||||
|
||||
bool TCPFileSystem::create()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void TCPFileSystem::destroy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
IFileSystem::Handle TCPFileSystem::openFile(const char* path, ReadCallback callback, void* user_data)
|
||||
{
|
||||
return LUX_NULL;
|
||||
}
|
||||
|
||||
|
||||
} // ~namespace Lux
|
|
@ -1,96 +0,0 @@
|
|||
#include "platform/native_file_system.h"
|
||||
#include "platform/task.h"
|
||||
#include "core/vector.h"
|
||||
#include <cstdio>
|
||||
#include "core/string.h"
|
||||
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
|
||||
class FileSystemTask : public MT::Task
|
||||
{
|
||||
public:
|
||||
virtual int task() LUX_OVERRIDE;
|
||||
|
||||
NativeFileSystemImpl* fs;
|
||||
};
|
||||
|
||||
|
||||
struct NativeFileSystemImpl
|
||||
{
|
||||
struct Info
|
||||
{
|
||||
FileSystem::OnFinished on_finished;
|
||||
void* data;
|
||||
string path;
|
||||
};
|
||||
|
||||
vector<Info> infos;
|
||||
FileSystemTask task;
|
||||
};
|
||||
|
||||
|
||||
int FileSystemTask::task()
|
||||
{
|
||||
bool finished = false;
|
||||
while(!finished)
|
||||
{
|
||||
if(!fs->infos.empty())
|
||||
{
|
||||
NativeFileSystemImpl::Info& h = fs->infos.back();
|
||||
|
||||
FILE* fp;
|
||||
fopen_s(&fp, h.path.c_str(), "r");
|
||||
if(fp)
|
||||
{
|
||||
fseek(fp, 0, SEEK_END);
|
||||
int size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
void* data = new char[size];
|
||||
fread(h.data, 1, size, fp);
|
||||
h.on_finished(h.path.c_str(), h.data, data, size, FileSystem::SUCCESS);
|
||||
delete[] data;
|
||||
}
|
||||
else
|
||||
{
|
||||
h.on_finished(h.path.c_str(), h.data, 0, 0, FileSystem::FAIL);
|
||||
}
|
||||
|
||||
fs->infos.pop_back();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool NativeFileSystem::create()
|
||||
{
|
||||
m_impl = new NativeFileSystemImpl();
|
||||
bool success = m_impl->task.create("NativeFileSystemTask");
|
||||
m_impl->task.fs = m_impl;
|
||||
success = success && m_impl->task.run();
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
void NativeFileSystem::destroy()
|
||||
{
|
||||
m_impl->task.destroy();
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
|
||||
void NativeFileSystem::open(const char* filename, OnFinished callback, void* data)
|
||||
{
|
||||
NativeFileSystemImpl::Info& info = m_impl->infos.push_back_empty();
|
||||
info.on_finished = callback;
|
||||
info.data = data;
|
||||
info.path = filename;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // ~namespace Lux
|
|
@ -1,227 +0,0 @@
|
|||
#include "platform/tcp_filesystem.h"
|
||||
#include "platform/task.h"
|
||||
#include "core/vector.h"
|
||||
#include "core/string.h"
|
||||
#include "platform/mutex.h"
|
||||
#include "platform/socket.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <cstdio>
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
struct TCPFileSystemTask : public MT::Task
|
||||
{
|
||||
virtual int task() LUX_OVERRIDE;
|
||||
void stop();
|
||||
void handleMessage(char* buffer, int size);
|
||||
|
||||
bool m_finished;
|
||||
MT::Mutex* m_mutex;
|
||||
struct TCPFileSystemImpl* m_fs;
|
||||
Net::Socket m_socket;
|
||||
Net::Socket* m_work_socket;
|
||||
};
|
||||
|
||||
|
||||
struct TCPFileSystemImpl
|
||||
{
|
||||
struct FileItem
|
||||
{
|
||||
enum Status
|
||||
{
|
||||
LOADING,
|
||||
SUCCESS,
|
||||
FAIL
|
||||
};
|
||||
string m_path;
|
||||
IFileSystem::ReadCallback m_callback;
|
||||
void* m_user_data;
|
||||
char* m_file_data;
|
||||
int m_file_length;
|
||||
int m_uid;
|
||||
Status m_status;
|
||||
};
|
||||
|
||||
TCPFileSystemTask* m_task;
|
||||
vector<FileItem*> m_queue;
|
||||
vector<FileItem*> m_loaded;
|
||||
vector<FileItem*> m_in_progress;
|
||||
int m_last_uid;
|
||||
};
|
||||
|
||||
|
||||
int TCPFileSystemTask::task()
|
||||
{
|
||||
char* buffer = new char[256];
|
||||
m_socket.create(NULL, 10001);
|
||||
m_work_socket = m_socket.accept();
|
||||
|
||||
m_finished = false;
|
||||
|
||||
while(!m_finished)
|
||||
{
|
||||
m_mutex->lock();
|
||||
if(!m_fs->m_queue.empty())
|
||||
{
|
||||
TCPFileSystemImpl::FileItem* item = m_fs->m_queue.back();
|
||||
m_fs->m_queue.pop_back();
|
||||
m_mutex->unlock();
|
||||
|
||||
int len = item->m_path.length() + 5;
|
||||
memcpy(buffer, &len, sizeof(len));
|
||||
buffer[4] = 0;
|
||||
memcpy(buffer+5, &item->m_uid, sizeof(item->m_uid));
|
||||
|
||||
m_work_socket->send(buffer, 9);
|
||||
m_work_socket->send(item->m_path.c_str(), item->m_path.length());
|
||||
|
||||
m_fs->m_in_progress.push_back(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mutex->unlock();
|
||||
}
|
||||
|
||||
char buffer2[256];
|
||||
if(m_work_socket->canReceive())
|
||||
{
|
||||
int received = m_work_socket->receive(buffer2, 5);
|
||||
handleMessage(buffer2, received);
|
||||
}
|
||||
}
|
||||
delete[] buffer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TCPFileSystemTask::handleMessage(char* buffer, int size)
|
||||
{
|
||||
if(size > 0)
|
||||
{
|
||||
if(size < 9)
|
||||
{
|
||||
if(!m_work_socket->receiveAllBytes(buffer + size, 9 - size))
|
||||
ASSERT(false);
|
||||
size = 9;
|
||||
}
|
||||
|
||||
int len = *(int*)buffer;
|
||||
if(buffer[4] == 0)
|
||||
{
|
||||
int uid = *(int*)(buffer + 5);
|
||||
bool found = false;
|
||||
for(int i = 0; i < m_fs->m_in_progress.size(); ++i)
|
||||
{
|
||||
if(m_fs->m_in_progress[i]->m_uid == uid)
|
||||
{
|
||||
if(len < 0)
|
||||
{
|
||||
m_fs->m_in_progress[i]->m_file_length = -1;
|
||||
m_fs->m_in_progress[i]->m_file_data = 0;
|
||||
m_fs->m_in_progress[i]->m_status = TCPFileSystemImpl::FileItem::FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fs->m_in_progress[i]->m_file_length = len - 5;
|
||||
m_fs->m_in_progress[i]->m_file_data = new char[len - 5];
|
||||
if(size > 9)
|
||||
memcpy(m_fs->m_in_progress[i]->m_file_data, buffer + 9, size - 9);
|
||||
m_work_socket->receiveAllBytes(m_fs->m_in_progress[i]->m_file_data + size - 9, len - size + 4);
|
||||
m_fs->m_in_progress[i]->m_status = TCPFileSystemImpl::FileItem::SUCCESS;
|
||||
}
|
||||
m_mutex->lock();
|
||||
m_fs->m_loaded.push_back(m_fs->m_in_progress[i]);
|
||||
m_fs->m_in_progress.eraseFast(i);
|
||||
m_mutex->unlock();
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
int last_err = WSAGetLastError();
|
||||
ASSERT(found);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TCPFileSystem::processLoaded()
|
||||
{
|
||||
m_impl->m_task->m_mutex->lock();
|
||||
if(!m_impl->m_loaded.empty())
|
||||
{
|
||||
TCPFileSystemImpl::FileItem* item = m_impl->m_loaded.back();
|
||||
m_impl->m_loaded.pop_back();
|
||||
m_impl->m_task->m_mutex->unlock();
|
||||
item->m_callback(item->m_user_data, item->m_file_data, item->m_file_length, item->m_status == TCPFileSystemImpl::FileItem::SUCCESS);
|
||||
delete item;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_impl->m_task->m_mutex->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TCPFileSystemTask::stop()
|
||||
{
|
||||
m_finished = true;
|
||||
}
|
||||
|
||||
|
||||
bool TCPFileSystem::create()
|
||||
{
|
||||
m_impl = new TCPFileSystemImpl();
|
||||
m_impl->m_last_uid = 0;
|
||||
m_impl->m_task = new TCPFileSystemTask();
|
||||
m_impl->m_task->m_fs = m_impl;
|
||||
if(!m_impl->m_task->create("TCP File System Task"))
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_impl->m_task->m_mutex = MT::Mutex::create("TCP File System Mutex");
|
||||
if(!m_impl->m_task->run())
|
||||
{
|
||||
m_impl->m_task->destroy();
|
||||
delete m_impl;
|
||||
m_impl = 0;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void TCPFileSystem::destroy()
|
||||
{
|
||||
if(m_impl)
|
||||
{
|
||||
m_impl->m_task->stop();
|
||||
MT::Mutex::destroy(m_impl->m_task->m_mutex);
|
||||
m_impl->m_task->destroy();
|
||||
delete m_impl;
|
||||
m_impl = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IFileSystem::Handle TCPFileSystem::openFile(const char* path, ReadCallback callback, void* user_data)
|
||||
{
|
||||
TCPFileSystemImpl::FileItem* item = new TCPFileSystemImpl::FileItem();
|
||||
item->m_callback = callback;
|
||||
item->m_path = path;
|
||||
item->m_user_data = user_data;
|
||||
item->m_uid = ++m_impl->m_last_uid;
|
||||
m_impl->m_task->m_mutex->lock();
|
||||
m_impl->m_queue.push_back(item);
|
||||
m_impl->m_task->m_mutex->unlock();
|
||||
return item->m_uid;
|
||||
}
|
||||
|
||||
|
||||
} // ~namespace Lux
|
|
@ -1,25 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include "core/ifilesystem.h"
|
||||
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
class LUX_PLATFORM_API TCPFileSystem : public IFileSystem
|
||||
{
|
||||
public:
|
||||
TCPFileSystem() { m_impl = 0; }
|
||||
|
||||
bool create();
|
||||
void destroy();
|
||||
void processLoaded();
|
||||
|
||||
virtual Handle openFile(const char* path, ReadCallback callback, void* user_data);
|
||||
|
||||
private:
|
||||
struct TCPFileSystemImpl* m_impl;
|
||||
};
|
||||
|
||||
} // ~namespace Lux
|
|
@ -2,6 +2,9 @@
|
|||
#include <Windows.h>
|
||||
#include <cstdio>
|
||||
#include "core/crc32.h"
|
||||
#include "core/file_system.h"
|
||||
#include "core/ifile.h"
|
||||
#include "engine/engine.h"
|
||||
#include "universe/universe.h"
|
||||
#include "universe/component_event.h"
|
||||
#include "base_script.h"
|
||||
|
@ -27,6 +30,7 @@ namespace Lux
|
|||
vector<HMODULE> m_libs;
|
||||
vector<string> m_paths;
|
||||
Universe* m_universe;
|
||||
Engine* m_engine;
|
||||
bool m_is_running;
|
||||
Renderer* m_renderer;
|
||||
InputSystem* m_input_system;
|
||||
|
@ -200,17 +204,16 @@ namespace Lux
|
|||
{
|
||||
char path[MAX_PATH];
|
||||
m_impl->getScriptDefaultPath(entity, path, MAX_PATH, "cpp");
|
||||
FILE* fp;
|
||||
fopen_s(&fp, path, "r");
|
||||
if(!fp)
|
||||
{
|
||||
fopen_s(&fp, path, "w");
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
FS::IFile* file = m_impl->m_engine->getFileSystem().open("memory:tcp", path, FS::Mode::OPEN_OR_CREATE);
|
||||
m_impl->m_engine->getFileSystem().close(file);
|
||||
|
||||
m_impl->m_scripts.push_back(entity.index);
|
||||
m_impl->m_paths.push_back(path);
|
||||
|
||||
Component cmp(entity, script_type, this, m_impl->m_scripts.size() - 1);
|
||||
m_impl->m_universe->getEventManager()->emitEvent(ComponentEvent(cmp));
|
||||
|
||||
return cmp;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue