Hey, i had my class setup and working, but it wasnt reading from the file and was being defined at the start of the main function.
So i added in a function which reads from the file the users settings, if it does exist it gets created, kinda simple (it worked 100% when i used local variables).
So then i decide to link it up to the classes variables to obviously get it globally, and i get a huge load of errors for each time these variables are called.
Errors: (yeah i was gona try and do a netstorm remake)
1>------ Build started: Project: Netstorm, Configuration: Debug Win32 ------
1>Compiling...
1>Core.cpp
1>Main.cpp
1>Generating Code...
1>Linking...
1>Main.obj : error LNK2001: unresolved external symbol "public: static int Core::SyncRate" (?SyncRate@Core@@2HA)
1>Core.obj : error LNK2001: unresolved external symbol "public: static int Core::SyncRate" (?SyncRate@Core@@2HA)
1>Main.obj : error LNK2001: unresolved external symbol "public: static int Core::WindowWidth" (?WindowWidth@Core@@2HA)
1>Core.obj : error LNK2001: unresolved external symbol "public: static int Core::WindowWidth" (?WindowWidth@Core@@2HA)
1>Main.obj : error LNK2001: unresolved external symbol "public: static int Core::WindowHeight" (?WindowHeight@Core@@2HA)
1>Core.obj : error LNK2001: unresolved external symbol "public: static int Core::WindowHeight" (?WindowHeight@Core@@2HA)
1>Main.obj : error LNK2001: unresolved external symbol "public: static int Core::ColourDepth" (?ColourDepth@Core@@2HA)
1>Core.obj : error LNK2001: unresolved external symbol "public: static int Core::ColourDepth" (?ColourDepth@Core@@2HA)
1>Main.obj : error LNK2001: unresolved external symbol "public: static bool Core::VSync" (?VSync@Core@@2_NA)
1>Core.obj : error LNK2001: unresolved external symbol "public: static bool Core::VSync" (?VSync@Core@@2_NA)
1>Core.obj : error LNK2001: unresolved external symbol "public: static bool Core::FullScreen" (?FullScreen@Core@@2_NA)
1>Debug\Netstorm.exe : fatal error LNK1120: 6 unresolved externals
1>Build log was saved at "file://d:\Netstorm\Netstorm\Debug\BuildLog.htm"
1>Netstorm - 12 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code for main.cpp: (17 lines)
#include <DarkGDK.h>
#include "Core.h"
void DarkGDK ( void )
{
Core::ReadSystemFile();
dbSetDisplayModeVSync(Core::WindowWidth,Core::WindowHeight,Core::ColourDepth,Core::VSync);
dbSyncOn();dbSyncRate(Core::SyncRate);dbSync();
while ( LoopGDK ( ) )
{
dbSync ( );
}
return;
}
Code for Core.h: (9 lines)
#pragma once
class Core
{
public:
static int WindowWidth, WindowHeight, ColourDepth, SyncRate;
static bool FullScreen, VSync;
static void ReadSystemFile();
};
Code for Core.cpp: (119 lines)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "Core.h"
void Core::ReadSystemFile()
{
const int charsize = 1000;
char file [charsize];
Core Temp;
for (int a = 0; a < charsize; a++)
file[a] = -1;
int c = 0 ;
//char file [1000];
FILE* fp = NULL;
fp = fopen("Config.ini", "r"); //r for read... w for write
if (fp != NULL) //if file exists
{
while (c < charsize) //read whole file
{
file[c] = fgetc (fp);
if (file[c] == -1)
break;
c++;
}
fclose(fp); //close file
c = 0;
while (true)
{
if (file[c] == '<')
{
c++;
char tag[20];
for (int a = 0; a < 20; a++)
tag[a] = -1;
int ctag = 0;
while (true) //read the tag
{
tag[ctag] = file[c];
c++;
ctag++;
if (file[c] == '=')
{
tag[ctag] = '\0';
break;
}
}
while (true) //get to the '
{
if (file[c] == '\'')
break;
c++;
}
c++; //moves it along 1
char content[20];
for (int a = 0; a < 20; a++)
content[a] = -1;
int cont = 0;
while (true)//read the contents
{
content[cont] = file[c];
c++;
cont++;
if (file[c] == '\'')
{
content[cont] = '\0';
break;
}
}
if (strcmp(tag,"FullScreen") == 0)
{
if (strcmp(content,"True") == 0)
Temp.FullScreen = true;
else
Temp.FullScreen = false;
}
else if (strcmp(tag,"VSync") == 0)
{
if (strcmp(content,"True") == 0)
Temp.VSync = true;
else
Temp.VSync = false;
}
else if (strcmp(tag,"SyncCap") == 0)
Temp.SyncRate = atoi(content);
else if (strcmp(tag,"ResolutionX") == 0)
Temp.WindowWidth = atoi(content);
else if (strcmp(tag,"ResolutionY") == 0)
Temp.WindowHeight = atoi(content);
else if (strcmp(tag,"ColourDepth") == 0)
Temp.ColourDepth = atoi(content);
}
c++;
if (c >= charsize)
break;
}
}
else
{
FILE * pFile;
pFile = fopen ("Config.ini","w");
if (pFile!=NULL)
{
fputs ("<FullScreen='True'/>\n<VSync='False'/>\n<SyncCap='0'/>\n<ResolutionX='1024'/>\n<ResolutionY='768'/>\n<ColourDepth='32'/>",pFile);
fclose (pFile);
}
}
}
I know im using the C and not the C++ library for reading files, but i find this way alot more logical. (also that isnt the error). The comments ive made are just notes for me so i remember what each part does when i look back at it in a few weeks.
I also realise i shouldnt use atoi without checking the string first, but this is really getting it working first.
Thanks in advance
Smoke me a kipper, ill be back for breakfast.