PDA

View Full Version : from .dll to .bundle


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

akb825
2007.01.20, 07:49 PM
The Mac equivalent of a dll would be a .dylib, or the wrappered version .framework. To make that, you're going to have to make a new target of the type you want, assuming you are using XCode. If not, you're going to have to pass -dynamiclib into gcc. If you want a framework, you'll have to create the directory and symbolic link structure yourself.

wyrmmage
2007.01.20, 08:23 PM
perfect :) With not too much pain I was able to compile it as a Cocoa framework ^_^
When I ship my game, will I need to include this graphics framework, or will merely linking against it be enough?
Thanks again :)
-wyrmmage

OneSadCookie
2007.01.21, 05:47 AM
.dylib and .frameworks are for linking to; .bundles are for loading dynamically at run-time.

wyrmmage
2007.01.21, 02:29 PM
ok. I guess .framework's were what I wanted then :)

Duane
2007.02.23, 06:11 PM
yes, you'll need to include them in App.app/Contents/Frameworks, so install is Drag-and-drop.