More work on levels

dev-mp
Krzysztof Dermont 2014-06-22 21:30:23 +02:00
parent 0556b5dfbc
commit 3aca1de731
5 changed files with 26 additions and 20 deletions

View File

@ -27,6 +27,7 @@ CResourceStreamBuffer::CResourceStreamBuffer(size_t buffer_size) : m_buffer_size
} }
m_buffer = new char[buffer_size]; m_buffer = new char[buffer_size];
m_file = nullptr;
} }

View File

@ -436,7 +436,7 @@ bool CModelFile::ReadModel(const std::string& fileName)
CInputStream stream; CInputStream stream;
stream.open(fileName.c_str()); stream.open(fileName.c_str());
if (!stream.good()) if (!stream.is_open())
{ {
GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); GetLogger()->Error("Could not open file '%s'\n", fileName.c_str());
return false; return false;
@ -827,7 +827,7 @@ bool CModelFile::ReadTextModel(const std::string& fileName)
{ {
CInputStream stream; CInputStream stream;
stream.open(fileName.c_str()); stream.open(fileName.c_str());
if (!stream.good()) if (!stream.is_open())
{ {
GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); GetLogger()->Error("Could not open file '%s'\n", fileName.c_str());
return false; return false;
@ -1024,7 +1024,7 @@ bool CModelFile::ReadBinaryModel(const std::string& fileName)
{ {
CInputStream stream; CInputStream stream;
stream.open(fileName.c_str()); stream.open(fileName.c_str());
if (!stream.good()) if (!stream.is_open())
{ {
GetLogger()->Error("Could not open file '%s'\n", fileName.c_str()); GetLogger()->Error("Could not open file '%s'\n", fileName.c_str());
return false; return false;

View File

@ -47,7 +47,7 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored)
if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS)) if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS))
modelFile.SetPrintDebugInfo(true); modelFile.SetPrintDebugInfo(true);
if (!modelFile.ReadModel(fileName)) if (!modelFile.ReadModel("models/" + fileName))
{ {
GetLogger()->Error("Loading model '%s' failed\n", fileName.c_str()); GetLogger()->Error("Loading model '%s' failed\n", fileName.c_str());
return false; return false;

View File

@ -29,6 +29,8 @@
#include "common/profile.h" #include "common/profile.h"
#include "common/restext.h" #include "common/restext.h"
#include "common/resources/inputstream.h"
#include "graphics/engine/camera.h" #include "graphics/engine/camera.h"
#include "graphics/engine/cloud.h" #include "graphics/engine/cloud.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
@ -4009,8 +4011,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
std::string tempLine; std::string tempLine;
m_dialog->BuildSceneName(tempLine, base, rank); m_dialog->BuildSceneName(tempLine, base, rank);
strcpy(filename, tempLine.c_str()); 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 rankObj = 0;
int rankGadget = 0; int rankGadget = 0;
@ -4023,7 +4028,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
* may speed up loading * may speed up loading
*/ */
while (fgets(line, 500, file) != NULL) while (stream.getline(line, 500))
{ {
lineNum++; lineNum++;
for (int i = 0; i < 500; i++) 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 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) if (read[0] == 0)
CompileScript(soluce); // compiles all scripts CompileScript(soluce); // compiles all scripts

View File

@ -24,6 +24,9 @@
#include "common/restext.h" #include "common/restext.h"
#include "common/stringutils.h" #include "common/stringutils.h"
#include "common/resources/inputstream.h"
#include "common/resources/resourcemanager.h"
#include "graphics/engine/terrain.h" #include "graphics/engine/terrain.h"
#include "graphics/engine/water.h" #include "graphics/engine/water.h"
#include "graphics/engine/text.h" #include "graphics/engine/text.h"
@ -50,6 +53,7 @@
#include "ui/edit.h" #include "ui/edit.h"
#include "ui/list.h" #include "ui/list.h"
#include "ui/displaytext.h" #include "ui/displaytext.h"
#include <test/cbot/CBot_console/CClass.h>
#include <stdio.h> #include <stdio.h>
@ -4363,7 +4367,6 @@ void CScript::GetError(std::string& error)
void CScript::New(Ui::CEdit* edit, const char* name) void CScript::New(Ui::CEdit* edit, const char* name)
{ {
FILE *file = NULL;
char res[100]; char res[100];
char text[100]; char text[100];
char script[500]; 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? if ( sf[0] != 0 ) // Load an empty program specific?
{ {
std::string filename = sf; std::string filename = sf;
file = fopen(filename.c_str(), "rb"); CInputStream stream;
if ( file != NULL ) stream.open(filename);
if (stream.is_open())
{ {
fseek(file, 0, SEEK_END); len = stream.size();
len = ftell(file);
fseek(file, 0, SEEK_SET);
if ( len > 500-1 ) len = 500-1; if ( len > 500-1 ) len = 500-1;
fread(buffer, 1, len, file); stream.read(buffer, len);
buffer[len] = 0; buffer[len] = 0;
fclose(file); stream.close();
cursor1 = 0; cursor1 = 0;
i = 0; i = 0;
@ -4494,12 +4497,9 @@ bool CScript::SendScript(const char* text)
bool CScript::ReadScript(const char* filename) bool CScript::ReadScript(const char* filename)
{ {
FILE* file;
Ui::CEdit* edit; Ui::CEdit* edit;
file = fopen(filename, "rb"); if (!CResourceManager::Exists(filename)) return false;
if ( file == NULL ) return false;
fclose(file);
delete[] m_script; delete[] m_script;
m_script = nullptr; m_script = nullptr;