summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Dermont <erihel@gmail.com>2014-06-22 21:30:23 +0200
committerKrzysztof Dermont <erihel@gmail.com>2014-06-22 21:30:23 +0200
commit3aca1de731fa7517db7d4dc00913542412150898 (patch)
treee508b93952b515fd7b0ea354b62cf71c33d4af3f
parent0556b5dfbcf8e3fe26ec4c773367d2f77e2c0ec9 (diff)
downloadcolobot-3aca1de731fa7517db7d4dc00913542412150898.tar.gz
colobot-3aca1de731fa7517db7d4dc00913542412150898.tar.bz2
colobot-3aca1de731fa7517db7d4dc00913542412150898.zip
More work on levels
-rw-r--r--src/common/resources/resourcestreambuffer.cpp1
-rw-r--r--src/graphics/engine/modelfile.cpp6
-rw-r--r--src/graphics/engine/modelmanager.cpp2
-rw-r--r--src/object/robotmain.cpp13
-rw-r--r--src/script/script.cpp24
5 files changed, 26 insertions, 20 deletions
diff --git a/src/common/resources/resourcestreambuffer.cpp b/src/common/resources/resourcestreambuffer.cpp
index e7be51d..ed6e738 100644
--- a/src/common/resources/resourcestreambuffer.cpp
+++ b/src/common/resources/resourcestreambuffer.cpp
@@ -27,6 +27,7 @@ CResourceStreamBuffer::CResourceStreamBuffer(size_t buffer_size) : m_buffer_size
}
m_buffer = new char[buffer_size];
+ m_file = nullptr;
}
diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp
index 0e3cbf8..5f10ff1 100644
--- a/src/graphics/engine/modelfile.cpp
+++ b/src/graphics/engine/modelfile.cpp
@@ -436,7 +436,7 @@ bool CModelFile::ReadModel(const std::string& fileName)
CInputStream stream;
stream.open(fileName.c_str());
- if (!stream.good())
+ if (!stream.is_open())
{
GetLogger()->Error("Could not open file '%s'\n", fileName.c_str());
return false;
@@ -827,7 +827,7 @@ bool CModelFile::ReadTextModel(const std::string& fileName)
{
CInputStream stream;
stream.open(fileName.c_str());
- if (!stream.good())
+ if (!stream.is_open())
{
GetLogger()->Error("Could not open file '%s'\n", fileName.c_str());
return false;
@@ -1024,7 +1024,7 @@ bool CModelFile::ReadBinaryModel(const std::string& fileName)
{
CInputStream stream;
stream.open(fileName.c_str());
- if (!stream.good())
+ if (!stream.is_open())
{
GetLogger()->Error("Could not open file '%s'\n", fileName.c_str());
return false;
diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp
index fc201fa..6ee0b86 100644
--- a/src/graphics/engine/modelmanager.cpp
+++ b/src/graphics/engine/modelmanager.cpp
@@ -47,7 +47,7 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored)
if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS))
modelFile.SetPrintDebugInfo(true);
- if (!modelFile.ReadModel(fileName))
+ if (!modelFile.ReadModel("models/" + fileName))
{
GetLogger()->Error("Loading model '%s' failed\n", fileName.c_str());
return false;
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 1c75137..87cd5fc 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -29,6 +29,8 @@
#include "common/profile.h"
#include "common/restext.h"
+#include "common/resources/inputstream.h"
+
#include "graphics/engine/camera.h"
#include "graphics/engine/cloud.h"
#include "graphics/engine/engine.h"
@@ -4009,8 +4011,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
std::string tempLine;
m_dialog->BuildSceneName(tempLine, base, rank);
strcpy(filename, tempLine.c_str());
- FILE* file = fopen(filename, "r");
- if (file == NULL) return;
+
+ CInputStream stream;
+ stream.open(filename);
+
+ if (!stream.is_open()) return;
int rankObj = 0;
int rankGadget = 0;
@@ -4023,7 +4028,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
* may speed up loading
*/
- while (fgets(line, 500, file) != NULL)
+ while (stream.getline(line, 500))
{
lineNum++;
for (int i = 0; i < 500; i++)
@@ -5062,7 +5067,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
GetLogger()->Error("Syntax error in file '%s' (line %d): Unknown command: %s", filename, lineNum, line); // Don't add \n at the end of log message - it's included in line variable
}
- fclose(file);
+ stream.close();
if (read[0] == 0)
CompileScript(soluce); // compiles all scripts
diff --git a/src/script/script.cpp b/src/script/script.cpp
index 11aa5c1..f59d27e 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -24,6 +24,9 @@
#include "common/restext.h"
#include "common/stringutils.h"
+#include "common/resources/inputstream.h"
+#include "common/resources/resourcemanager.h"
+
#include "graphics/engine/terrain.h"
#include "graphics/engine/water.h"
#include "graphics/engine/text.h"
@@ -50,6 +53,7 @@
#include "ui/edit.h"
#include "ui/list.h"
#include "ui/displaytext.h"
+#include <test/cbot/CBot_console/CClass.h>
#include <stdio.h>
@@ -4363,7 +4367,6 @@ void CScript::GetError(std::string& error)
void CScript::New(Ui::CEdit* edit, const char* name)
{
- FILE *file = NULL;
char res[100];
char text[100];
char script[500];
@@ -4407,17 +4410,17 @@ void CScript::New(Ui::CEdit* edit, const char* name)
if ( sf[0] != 0 ) // Load an empty program specific?
{
std::string filename = sf;
- file = fopen(filename.c_str(), "rb");
- if ( file != NULL )
+ CInputStream stream;
+ stream.open(filename);
+
+ if (stream.is_open())
{
- fseek(file, 0, SEEK_END);
- len = ftell(file);
- fseek(file, 0, SEEK_SET);
+ len = stream.size();
if ( len > 500-1 ) len = 500-1;
- fread(buffer, 1, len, file);
+ stream.read(buffer, len);
buffer[len] = 0;
- fclose(file);
+ stream.close();
cursor1 = 0;
i = 0;
@@ -4494,12 +4497,9 @@ bool CScript::SendScript(const char* text)
bool CScript::ReadScript(const char* filename)
{
- FILE* file;
Ui::CEdit* edit;
- file = fopen(filename, "rb");
- if ( file == NULL ) return false;
- fclose(file);
+ if (!CResourceManager::Exists(filename)) return false;
delete[] m_script;
m_script = nullptr;