wyrmmage
2007.01.20, 06:00 PM
First off: I know that I posted related to this earlier about how to do this, but now that I'm actually doing it, I need a bit more help.
I'm transferring my .dll files to .bundle files on the Mac; I'm not really using .dll files for their true purpose, instead I'm just basically using them to export the classes that they contain; while some may say that this is pointless, it has simplified the development of my game quite a bit, which is what I was aiming for.
Here is the header file of the .dll on windows:
#ifndef OBJECTMANAGER_HPP
#define OBJECTMANAGER_HPP
#include "object.hpp"
class __declspec(dllexport) objectManager
{
public:
object* objects;
object boundingCube;
int numberOfObjects;
double offsetX;
double offsetY;
double offsetZ;
objectManager();
void copyConstructor(objectManager* copiedObjectManager);
~objectManager();
void loadObjects(const char* theManagerName);
void moveX(double addX);
void moveY(double addY);
void moveZ(double addZ);
void draw();
void drawBounding();
};
#endif
and the .cpp file:
#include "objectManager.hpp"
using namespace std;
objectManager::objectManager()
{
numberOfObjects = 0;
offsetX = 0.0;
offsetY = 0.0;
offsetZ = 0.0;
boundingCube.shapes = new shape[6];
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].constructor(3);
}
}
void objectManager::copyConstructor(objectManager* copiedObjectManager)
{
offsetX = copiedObjectManager->offsetX;
offsetY = copiedObjectManager->offsetY;
offsetZ = copiedObjectManager->offsetZ;
numberOfObjects = copiedObjectManager->numberOfObjects;
objects = new object[numberOfObjects+1];
for(int i=0; i<=numberOfObjects; i++)
{
objects[i].copyConstructor(&copiedObjectManager->objects[i]);
}
for(int i=0; i<=5; i++)
{
for(int x=0; x<=3; x++)
{
boundingCube.shapes[i].setCurrentXYZ(copiedObjectManager->boundingCube.shapes[i].vertices[x].getX(), copiedObjectManager->boundingCube.shapes[i].vertices[x].getY(), copiedObjectManager->boundingCube.shapes[i].vertices[x].getZ());
}
}
}
objectManager::~objectManager()
{
delete [] objects;
}
void objectManager::loadObjects(const char* theManagerName)
{
#if defined(__APPLE_CC__)
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
fprintf(stderr, "Can't change to Resources direcory; something's seriously wrong\n");
exit(EXIT_FAILURE);
}
CFRelease(resourcesURL);
int dotOperatorPos = 0;
while(path[dotOperatorPos] != '.')
{
dotOperatorPos = dotOperatorPos + 1;
}
path[(dotOperatorPos + 3)] = '\0';
path[(dotOperatorPos + 2)] = '\0';
path[(dotOperatorPos + 1)] = '\0';
path[dotOperatorPos] = '\0';
for(int i=dotOperatorPos;path[i] != '/';i--)
{
path[i] = '\0';
}
chdir(path);
#endif
FILE * readFile;
std::string temporaryFileName = std::string("Objects/") + theManagerName + std::string("/meshList.txt");
char parameterFile[temporaryFileName.length()];
for(int x=0;x<=temporaryFileName.length();x++)
{
parameterFile[x] = temporaryFileName[x];
}
readFile = fopen(parameterFile,"r+t");
if(readFile)
{
fscanf(readFile, "%d", &numberOfObjects);
objects = new object[numberOfObjects+1];
char tempObjectName[20];
for(int i=0; i<=numberOfObjects; i++)
{
fscanf(readFile, "%s", &tempObjectName);
objects[i].loadShapes(theManagerName, tempObjectName);
}
fclose(readFile);
}
double tempX = 0.0;
double tempY = 0.0;
double tempZ = 0.0;
for(int i=0; i<=numberOfObjects; i++)
{
if(objects[i].boundingX > tempX)
{
tempX = objects[i].boundingX;
}
if(objects[i].boundingY > tempY)
{
tempY = objects[i].boundingY;
}
if(objects[i].boundingZ > tempZ)
{
tempZ = objects[i].boundingZ;
}
}
boundingCube.shapes[0].setCurrentXYZ((tempX * -1), (tempY * -1), (tempZ * -1));
boundingCube.shapes[0].setCurrentXYZ(tempX, (tempY * -1), (tempZ * -1));
boundingCube.shapes[0].setCurrentXYZ(tempX, tempY, (tempZ * -1));
boundingCube.shapes[0].setCurrentXYZ((tempX * -1), tempY, (tempZ * -1));
boundingCube.shapes[1].setCurrentXYZ((tempX * -1), (tempY * -1), (tempZ * -1));
boundingCube.shapes[1].setCurrentXYZ((tempX * -1), (tempY * -1), tempZ);
boundingCube.shapes[1].setCurrentXYZ((tempX * -1), tempY, tempZ);
boundingCube.shapes[1].setCurrentXYZ((tempX * -1), tempY, (tempZ * -1));
boundingCube.shapes[2].setCurrentXYZ((tempX * -1), (tempY * -1), tempZ);
boundingCube.shapes[2].setCurrentXYZ(tempX, (tempY * -1), tempZ);
boundingCube.shapes[2].setCurrentXYZ(tempX, tempY, tempZ);
boundingCube.shapes[2].setCurrentXYZ((tempX * -1), tempY, tempZ);
boundingCube.shapes[3].setCurrentXYZ(tempX, (tempY * -1), (tempZ * -1));
boundingCube.shapes[3].setCurrentXYZ(tempX, (tempY * -1), tempZ);
boundingCube.shapes[3].setCurrentXYZ(tempX, tempY, tempZ);
boundingCube.shapes[3].setCurrentXYZ(tempX, tempY, (tempZ * -1));
boundingCube.shapes[4].setCurrentXYZ((tempX * -1), tempY, (tempZ * -1));
boundingCube.shapes[4].setCurrentXYZ((tempX * -1), tempY, tempZ);
boundingCube.shapes[4].setCurrentXYZ(tempX, tempY, tempZ);
boundingCube.shapes[4].setCurrentXYZ(tempX, tempY, (tempZ * -1));
boundingCube.shapes[5].setCurrentXYZ((tempX * -1), (tempY * -1), (tempZ * -1));
boundingCube.shapes[5].setCurrentXYZ((tempX * -1), (tempY * -1), tempZ);
boundingCube.shapes[5].setCurrentXYZ(tempX, (tempY * -1), tempZ);
boundingCube.shapes[5].setCurrentXYZ(tempX, (tempY * -1), (tempZ * -1));
}
void objectManager::moveX(double addX)
{
offsetX = offsetX + addX;
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].moveX(addX);
}
for(int i=0; i<=numberOfObjects; i++)
{
objects[i].boundingSquare.moveX(addX);
}
}
void objectManager::moveY(double addY)
{
offsetY = offsetY + addY;
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].moveY(addY);
}
for(int i=0; i<=numberOfObjects; i++)
{
objects[i].boundingSquare.moveY(addY);
}
}
void objectManager::moveZ(double addZ)
{
offsetZ = offsetZ + addZ;
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].moveZ(addZ);
}
for(int i=0; i<=numberOfObjects; i++)
{
objects[i].boundingSquare.moveZ(addZ);
}
}
void objectManager::draw()
{
glTranslatef(offsetX, offsetY, offsetZ);
for(int i=0;i<=numberOfObjects;i++)
{
objects[i].draw();
}
glTranslatef((-1*offsetX),(-1*offsetY),(-1*offsetZ));
}
void objectManager::drawBounding()
{
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].drawNoTexture();
}
}
I've successfully compiled my program both on Mac and on Windows (on Windows as a .dll file and on Mac as a .app), all I need to do now is to add in the code to make it a .bundle file; unfortunately, I have no idea how to do this. Half an hour of googling such terms as 'bundle programming','mac bundles', etc. have been rather fruitless, as has the Mac Developer's articles on bundles.
Thanks :)
-wyrmmage
I'm transferring my .dll files to .bundle files on the Mac; I'm not really using .dll files for their true purpose, instead I'm just basically using them to export the classes that they contain; while some may say that this is pointless, it has simplified the development of my game quite a bit, which is what I was aiming for.
Here is the header file of the .dll on windows:
#ifndef OBJECTMANAGER_HPP
#define OBJECTMANAGER_HPP
#include "object.hpp"
class __declspec(dllexport) objectManager
{
public:
object* objects;
object boundingCube;
int numberOfObjects;
double offsetX;
double offsetY;
double offsetZ;
objectManager();
void copyConstructor(objectManager* copiedObjectManager);
~objectManager();
void loadObjects(const char* theManagerName);
void moveX(double addX);
void moveY(double addY);
void moveZ(double addZ);
void draw();
void drawBounding();
};
#endif
and the .cpp file:
#include "objectManager.hpp"
using namespace std;
objectManager::objectManager()
{
numberOfObjects = 0;
offsetX = 0.0;
offsetY = 0.0;
offsetZ = 0.0;
boundingCube.shapes = new shape[6];
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].constructor(3);
}
}
void objectManager::copyConstructor(objectManager* copiedObjectManager)
{
offsetX = copiedObjectManager->offsetX;
offsetY = copiedObjectManager->offsetY;
offsetZ = copiedObjectManager->offsetZ;
numberOfObjects = copiedObjectManager->numberOfObjects;
objects = new object[numberOfObjects+1];
for(int i=0; i<=numberOfObjects; i++)
{
objects[i].copyConstructor(&copiedObjectManager->objects[i]);
}
for(int i=0; i<=5; i++)
{
for(int x=0; x<=3; x++)
{
boundingCube.shapes[i].setCurrentXYZ(copiedObjectManager->boundingCube.shapes[i].vertices[x].getX(), copiedObjectManager->boundingCube.shapes[i].vertices[x].getY(), copiedObjectManager->boundingCube.shapes[i].vertices[x].getZ());
}
}
}
objectManager::~objectManager()
{
delete [] objects;
}
void objectManager::loadObjects(const char* theManagerName)
{
#if defined(__APPLE_CC__)
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
fprintf(stderr, "Can't change to Resources direcory; something's seriously wrong\n");
exit(EXIT_FAILURE);
}
CFRelease(resourcesURL);
int dotOperatorPos = 0;
while(path[dotOperatorPos] != '.')
{
dotOperatorPos = dotOperatorPos + 1;
}
path[(dotOperatorPos + 3)] = '\0';
path[(dotOperatorPos + 2)] = '\0';
path[(dotOperatorPos + 1)] = '\0';
path[dotOperatorPos] = '\0';
for(int i=dotOperatorPos;path[i] != '/';i--)
{
path[i] = '\0';
}
chdir(path);
#endif
FILE * readFile;
std::string temporaryFileName = std::string("Objects/") + theManagerName + std::string("/meshList.txt");
char parameterFile[temporaryFileName.length()];
for(int x=0;x<=temporaryFileName.length();x++)
{
parameterFile[x] = temporaryFileName[x];
}
readFile = fopen(parameterFile,"r+t");
if(readFile)
{
fscanf(readFile, "%d", &numberOfObjects);
objects = new object[numberOfObjects+1];
char tempObjectName[20];
for(int i=0; i<=numberOfObjects; i++)
{
fscanf(readFile, "%s", &tempObjectName);
objects[i].loadShapes(theManagerName, tempObjectName);
}
fclose(readFile);
}
double tempX = 0.0;
double tempY = 0.0;
double tempZ = 0.0;
for(int i=0; i<=numberOfObjects; i++)
{
if(objects[i].boundingX > tempX)
{
tempX = objects[i].boundingX;
}
if(objects[i].boundingY > tempY)
{
tempY = objects[i].boundingY;
}
if(objects[i].boundingZ > tempZ)
{
tempZ = objects[i].boundingZ;
}
}
boundingCube.shapes[0].setCurrentXYZ((tempX * -1), (tempY * -1), (tempZ * -1));
boundingCube.shapes[0].setCurrentXYZ(tempX, (tempY * -1), (tempZ * -1));
boundingCube.shapes[0].setCurrentXYZ(tempX, tempY, (tempZ * -1));
boundingCube.shapes[0].setCurrentXYZ((tempX * -1), tempY, (tempZ * -1));
boundingCube.shapes[1].setCurrentXYZ((tempX * -1), (tempY * -1), (tempZ * -1));
boundingCube.shapes[1].setCurrentXYZ((tempX * -1), (tempY * -1), tempZ);
boundingCube.shapes[1].setCurrentXYZ((tempX * -1), tempY, tempZ);
boundingCube.shapes[1].setCurrentXYZ((tempX * -1), tempY, (tempZ * -1));
boundingCube.shapes[2].setCurrentXYZ((tempX * -1), (tempY * -1), tempZ);
boundingCube.shapes[2].setCurrentXYZ(tempX, (tempY * -1), tempZ);
boundingCube.shapes[2].setCurrentXYZ(tempX, tempY, tempZ);
boundingCube.shapes[2].setCurrentXYZ((tempX * -1), tempY, tempZ);
boundingCube.shapes[3].setCurrentXYZ(tempX, (tempY * -1), (tempZ * -1));
boundingCube.shapes[3].setCurrentXYZ(tempX, (tempY * -1), tempZ);
boundingCube.shapes[3].setCurrentXYZ(tempX, tempY, tempZ);
boundingCube.shapes[3].setCurrentXYZ(tempX, tempY, (tempZ * -1));
boundingCube.shapes[4].setCurrentXYZ((tempX * -1), tempY, (tempZ * -1));
boundingCube.shapes[4].setCurrentXYZ((tempX * -1), tempY, tempZ);
boundingCube.shapes[4].setCurrentXYZ(tempX, tempY, tempZ);
boundingCube.shapes[4].setCurrentXYZ(tempX, tempY, (tempZ * -1));
boundingCube.shapes[5].setCurrentXYZ((tempX * -1), (tempY * -1), (tempZ * -1));
boundingCube.shapes[5].setCurrentXYZ((tempX * -1), (tempY * -1), tempZ);
boundingCube.shapes[5].setCurrentXYZ(tempX, (tempY * -1), tempZ);
boundingCube.shapes[5].setCurrentXYZ(tempX, (tempY * -1), (tempZ * -1));
}
void objectManager::moveX(double addX)
{
offsetX = offsetX + addX;
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].moveX(addX);
}
for(int i=0; i<=numberOfObjects; i++)
{
objects[i].boundingSquare.moveX(addX);
}
}
void objectManager::moveY(double addY)
{
offsetY = offsetY + addY;
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].moveY(addY);
}
for(int i=0; i<=numberOfObjects; i++)
{
objects[i].boundingSquare.moveY(addY);
}
}
void objectManager::moveZ(double addZ)
{
offsetZ = offsetZ + addZ;
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].moveZ(addZ);
}
for(int i=0; i<=numberOfObjects; i++)
{
objects[i].boundingSquare.moveZ(addZ);
}
}
void objectManager::draw()
{
glTranslatef(offsetX, offsetY, offsetZ);
for(int i=0;i<=numberOfObjects;i++)
{
objects[i].draw();
}
glTranslatef((-1*offsetX),(-1*offsetY),(-1*offsetZ));
}
void objectManager::drawBounding()
{
for(int i=0; i<=5; i++)
{
boundingCube.shapes[i].drawNoTexture();
}
}
I've successfully compiled my program both on Mac and on Windows (on Windows as a .dll file and on Mac as a .app), all I need to do now is to add in the code to make it a .bundle file; unfortunately, I have no idea how to do this. Half an hour of googling such terms as 'bundle programming','mac bundles', etc. have been rather fruitless, as has the Mac Developer's articles on bundles.
Thanks :)
-wyrmmage