Please check it out, give me a tip, tell me what I'm doing wrong, etc.. heres what I got so far ->
Script.h
Code: Select all
#ifndef __SCRIPT_H
#define __SCRIPT_H
#include "Globals.h"
#include "Entity.h"
namespace GroundUpEngine
{
class Script {
// Class Private Variables //
private:
ifstream script;
int object_count;
list<Entity*>Entitys;
list<Entity*>::iterator node;
public:
// De/Constructor //
Script();
~Script();
// Script Functions //
void Read();
};
} // namespace GroundUpEngine
#endif // __SCRIPT_H
Code: Select all
#include "Script.h"
namespace GroundUpEngine
{
// ---------------------------------------- De/Constructor ---------------------------------------- //
Script::Script()
{
object_count = 0;
}
Script::~Script()
{
node = Entitys.begin();
while(node != Entitys.end())
{
if((*node) != NULL)
{
delete *node;
*node = NULL;
}
++node;
}
}
// ---------------------------------------- Script Functions ---------------------------------------- //
void Script::Read()
{
cout << "What script do you want run?\t";
string filename;
cin >> filename;
script.open(filename.c_str());
// Loop Until end of File //
while(!script.eof())
{
string temp;
// Read for engine commands //
script >> temp;
if(temp == "object")
{
object_count++;
cout << "\nLoading Object..." << endl;
Entitys.push_back(new Entity);
node = Entitys.begin();
string temp;
script >> temp;
(*node)->index = atoi(temp.c_str());
script >> temp;
(*node)->mesh_name = temp;
script >> temp;
(*node)->texture_name = temp;
cout << "Object Number: " << (*node)->index << endl;
cout << "Object Mesh: " << (*node)->mesh_name << endl;
cout << "Object Texture: " << (*node)->texture_name << endl;
++node;//Increment object count
}
if(temp == "position")
{
cout << "\nInitializing Object..." << endl;
list<Entity*>::iterator temp_node = Entitys.begin();
string temp;
int temp_index;
script >> temp;
temp_index = atoi(temp.c_str());
for(int i = 0; i <= temp_index; i++)
{
++temp_node;
}
script >> temp;
(*temp_node)->x = atoi(temp.c_str());
script >> temp;
(*temp_node)->y = atoi(temp.c_str());
script >> temp;
(*temp_node)->z = atoi(temp.c_str());
cout << "Object Number: " << temp_index << endl;
cout << "Object Position: " << (*temp_node)->x << ", "
<< (*temp_node)->y << ", " << (*temp_node)->z << endl;
}
}
script.close();
cout << "\nObject's In Level: " << object_count << endl;
}
} // namespace GroundUpEngine
Code: Select all
object 1 Crate.obj Crate.png
position 1 0 0 0