Cleaned up useless code and comments

This commit is contained in:
andreja6
2018-05-02 17:04:36 -07:00
parent e04f53c071
commit 29dad6bd8d
2 changed files with 112 additions and 307 deletions

View File

@@ -2,6 +2,7 @@
DataModelInstance* Globals::dataModel = NULL; DataModelInstance* Globals::dataModel = NULL;
Globals::Globals(void) Globals::Globals(void)
{ {

418
main.cpp
View File

@@ -73,11 +73,6 @@ Vector2 oldMouse = Vector2(0,0);
float moveRate = 0.5; float moveRate = 0.5;
Instance* selectedInstance = NULL; Instance* selectedInstance = NULL;
class Demo : public GApplet { class Demo : public GApplet {
public: public:
@@ -170,10 +165,6 @@ Demo::Demo(App* _app) : GApplet(_app), app(_app) {
void clearInstances() void clearInstances()
{ {
//for(size_t i = 0; i < instances.size(); i++)
//{
// delete instances.at(i);
//}
delete dataModel; delete dataModel;
} }
@@ -183,7 +174,6 @@ void OnError(int err, std::string msg = "")
usableApp->window()->setMouseVisible(true); usableApp->window()->setMouseVisible(true);
std::string emsg = "An unexpected error has occured and DUOM 5 has to quit. We're sorry!" + msg; std::string emsg = "An unexpected error has occured and DUOM 5 has to quit. We're sorry!" + msg;
clearInstances(); clearInstances();
//DialogBox(NULL, MAKEINTRESOURCE(IDD_DIALOG1), NULL, NULL);
MessageBox(NULL, emsg.c_str(),"Dynamica Crash", MB_OK); MessageBox(NULL, emsg.c_str(),"Dynamica Crash", MB_OK);
exit(err); exit(err);
} }
@@ -221,15 +211,12 @@ std::string Convert (float number){
PhysicalInstance* makePart() PhysicalInstance* makePart()
{ {
PhysicalInstance* part = new PhysicalInstance(); PhysicalInstance* part = new PhysicalInstance();
// instances.push_back(part);
return part; return part;
} }
TextButtonInstance* makeTextButton() TextButtonInstance* makeTextButton()
{ {
TextButtonInstance* part = new TextButtonInstance(); TextButtonInstance* part = new TextButtonInstance();
// instances.push_back(part);
// instances_2D.push_back(part);
return part; return part;
} }
@@ -713,7 +700,6 @@ void Demo::onInit() {
test->setSize(Vector3(24,1,24)); test->setSize(Vector3(24,1,24));
test->setPosition(Vector3(0,0,0)); test->setPosition(Vector3(0,0,0));
test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(40),toRadians(40))); test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(40),toRadians(40)));
//selectedInstance = test;
@@ -843,10 +829,10 @@ void Demo::onNetwork() {
} }
double getVectorDistance(Vector3 vector1, Vector3 vector2) //double getVectorDistance(Vector3 vector1, Vector3 vector2)
{ //{
return pow(pow((double)vector1.x - (double)vector2.x, 2) + pow((double)vector1.y - (double)vector2.y, 2) + pow((double)vector1.z - (double)vector2.z, 2), 0.5); // return pow(pow((double)vector1.x - (double)vector2.x, 2) + pow((double)vector1.y - (double)vector2.y, 2) + pow((double)vector1.z - (double)vector2.z, 2), 0.5);
} //}
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
if(dataModel->name != title) if(dataModel->name != title)
@@ -903,49 +889,6 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
newFrame.lookAt(focus); newFrame.lookAt(focus);
app->debugController.setCoordinateFrame(newFrame); app->debugController.setCoordinateFrame(newFrame);
/*Vector3 camerapoint = frame.translation;
Vector3 focalPoint = camerapoint + frame.lookVector() * 25;
float distb = getVectorDistance(Vector3(focalPoint.x, camerapoint.y, focalPoint.z), Vector3(camerapoint.x, camerapoint.y, focalPoint.z));
float distc = abs(((float)getVectorDistance(Vector3(focalPoint.x, camerapoint.y, focalPoint.z), camerapoint)));
float angle = atan2(camerapoint.z - focalPoint.z, focalPoint.x - camerapoint.x);
//message = Convert(angle);
messageTime = System::time();
//frame.rotation.toEulerAnglesXYZ(x, angle, z);
//angle = toDegrees(angle);
// if(camerapoint.z < focalPoint.z)
// {
// float angleadd = abs(angle - 90);
// angle = angleadd + 5 + 90;
// }
// else
// {
// angle = angle + 5;
// }
messageTime = System::time();
//abs(((float)(getVectorDistance(Vector3(focalPoint.x, camerapoint.y, focalPoint.z), camerapoint))));
float x = distc * cos(angle + toRadians(2)) + focalPoint.x;
float z = distc * sin(angle + toRadians(2)) + focalPoint.z;
message = "NOT 0, " + Convert(toDegrees(angle)) + ", " + Convert(toDegrees(angle + toRadians(2)));
//camerapoint = Vector3(sin(angle)*distc,camerapoint.y,cos(angle)*distc);
camerapoint = Vector3(x,camerapoint.y,z);
CoordinateFrame newFrame = CoordinateFrame(camerapoint);
newFrame.lookAt(focalPoint);
cameraPos = camerapoint;
app->debugController.setCoordinateFrame(newFrame);*/
} }
if(panLeft) if(panLeft)
{ {
@@ -983,13 +926,7 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
} }
/*double getOSVersion() {
//void readMouseGUIInput()
//{
//}
double getOSVersion() {
OSVERSIONINFO osvi; OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
@@ -998,7 +935,7 @@ double getOSVersion() {
GetVersionEx(&osvi); GetVersionEx(&osvi);
std::string version = Convert(osvi.dwMajorVersion) + "." + Convert(osvi.dwMinorVersion); std::string version = Convert(osvi.dwMajorVersion) + "." + Convert(osvi.dwMinorVersion);
return ::atof(version.c_str()); return ::atof(version.c_str());
} }*/
//User Input //User Input
void Demo::onUserInput(UserInput* ui) { void Demo::onUserInput(UserInput* ui) {
@@ -1066,25 +1003,12 @@ void Demo::onUserInput(UserInput* ui) {
app->setDebugMode(!app->debugMode()); app->setDebugMode(!app->debugMode());
} }
} }
if(ui->keyDown(SDLK_LCTRL)) //if(ui->keyPressed(SDLK_F8))
{ //{
if(ui->keyPressed('v')) // messageTime = System::time();
{ // message = "FPS has been locked at " + Convert(FPSVal[index]);
messageTime = System::time();
message = Convert(getOSVersion());
}
}
if(ui->keyPressed(SDLK_F8))
{
//index++;
//if(index >= 7)
//{
// index = 0;
//}
messageTime = System::time();
message = "FPS has been locked at " + Convert(FPSVal[index]);
//setDesiredFrameRate(FPSVal[index]); //setDesiredFrameRate(FPSVal[index]);
} //}
dataModel->mousex = ui->getMouseX(); dataModel->mousex = ui->getMouseX();
dataModel->mousey = ui->getMouseY(); dataModel->mousey = ui->getMouseY();
dataModel->mouseButton1Down = ui->keyDown(SDL_LEFT_MOUSE_KEY); dataModel->mouseButton1Down = ui->keyDown(SDL_LEFT_MOUSE_KEY);
@@ -1216,7 +1140,6 @@ void makeFlag(Vector3 &vec, RenderDevice* &rd)
{ {
Vector3 up = Vector3(vec.x, vec.y+3, vec.z); Vector3 up = Vector3(vec.x, vec.y+3, vec.z);
//Draw::lineSegment(G3D::LineSegment::fromTwoPoints(vec, up), rd, Color3::blue(), 3);
rd->setColor(Color3::blue()); rd->setColor(Color3::blue());
rd->beforePrimitive(); rd->beforePrimitive();
@@ -1260,23 +1183,11 @@ bool mouseInArea(float point1x, float point1y, float point2x, float point2y)
void drawButtons(RenderDevice* rd) void drawButtons(RenderDevice* rd)
{ {
dataModel->getGuiRoot()->render(rd); dataModel->getGuiRoot()->render(rd);
/*std::vector<Instance*> instances_2D = dataModel->getGuiRoot()->getChildren();
for(size_t i = 0; i < instances_2D.size(); i++)
{
Instance* instance = instances_2D.at(i);
if(instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton")
{
BaseButtonInstance* tbi = (BaseButtonInstance*)instance;
tbi->drawObj(rd, Vector2(dataModel->mousex, dataModel->mousey), dataModel->mouseButton1Down);
}
}*/
} }
void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters lighting, Vector3 size, Vector3 pos, CoordinateFrame c) void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters lighting, Vector3 size, Vector3 pos, CoordinateFrame c)
{ {
//rd->setLight(0, NULL);
//rd->setAmbientLightColor(Color3(1,1,1));
Color3 outline = Color3::cyan();//Color3(0.098F,0.6F,1.0F); Color3 outline = Color3::cyan();//Color3(0.098F,0.6F,1.0F);
float offsetSize = 0.05F; float offsetSize = 0.05F;
//X //X
@@ -1325,7 +1236,6 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters
} }
else if(mode == RESIZE) else if(mode == RESIZE)
{ {
//Box box = c.toWorldSpace(Box(from, to))
Color3 sphereColor = outline; Color3 sphereColor = outline;
rd->setLight(0, NULL); rd->setLight(0, NULL);
rd->setAmbientLightColor(Color3(1,1,1)); rd->setAmbientLightColor(Color3(1,1,1));
@@ -1352,13 +1262,6 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear()); Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos - (c.upVector()*((size.y/2)+1)); position = pos - (c.upVector()*((size.y/2)+1));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear()); Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
//Draw::sphere(Sphere(Vector3(pos.x, pos.y - (size.y/2 + 1), pos.z), multiplier), rd, sphereColor, Color4::clear());
//Draw::sphere(Sphere(Vector3(pos.x + (size.x/2 + 1), pos.y, pos.z), multiplier), rd, sphereColor, Color4::clear());
//Draw::sphere(Sphere(Vector3(pos.x - (size.x/2 + 1), pos.y, pos.z), multiplier), rd, sphereColor, Color4::clear());
//Draw::sphere(Sphere(Vector3(pos.x, pos.y, pos.z + (size.z/2 + 1)), multiplier), rd, sphereColor, Color4::clear());
//Draw::sphere(Sphere(Vector3(pos.x, pos.y, pos.z - (size.z/2 + 1)), multiplier), rd, sphereColor, Color4::clear());
} }
rd->setAmbientLightColor(lighting.ambient); rd->setAmbientLightColor(lighting.ambient);
rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
@@ -1372,35 +1275,9 @@ void Demo::exitApplication()
app->endProgram = true; app->endProgram = true;
} }
void makeBeveledBox(Box box, RenderDevice* rd, Color4 color, CoordinateFrame cFrame)
{
Vector3 v0, v1, v2, v3;
//glDiffuse();
rd->setColor(color);
rd->setObjectToWorldMatrix(CoordinateFrame());
rd->beginPrimitive(RenderDevice::QUADS);
for (int f = 0; f < 6; ++f) {
box.getFaceCorners(f, v0, v1, v2, v3);
glShadeModel(GL_SMOOTH);
//rd->setNormal((v1 - v0).cross(v3 - v0).direction());
rd->sendVertex(v0);
rd->sendVertex(v1);
rd->sendVertex(v2);
rd->sendVertex(v3);
}
rd->setColor(Color3::white());
rd->endPrimitive();
}
void Demo::onGraphics(RenderDevice* rd) { void Demo::onGraphics(RenderDevice* rd) {
float angle, x, z;
app->debugCamera.getCoordinateFrame().rotation.toEulerAnglesXYZ(x, angle, z);
//message = Convert(toDegrees(angle)) + " X: " + Convert(app->debugCamera.getCoordinateFrame().translation.x) + " Z: " + Convert(app->debugCamera.getCoordinateFrame().translation.z);
//messageTime = System::time();
CoordinateFrame frame = CoordinateFrame(app->debugCamera.getCoordinateFrame().rotation, app->debugCamera.getCoordinateFrame().translation);
Vector2 mousepos = Vector2(0,0); Vector2 mousepos = Vector2(0,0);
G3D::uint8 num = 0; G3D::uint8 num = 0;
rd->window()->getRelativeMouseState(mousepos, num); rd->window()->getRelativeMouseState(mousepos, num);
@@ -1425,7 +1302,7 @@ void Demo::onGraphics(RenderDevice* rd) {
// Cyan background // Cyan background
app->renderDevice->setColorClearValue(Color3(0.0f, 0.5f, 1.0f)); //app->renderDevice->setColorClearValue(Color3(0.0f, 0.5f, 1.0f));
app->renderDevice->clear(app->sky.isNull(), true, true); app->renderDevice->clear(app->sky.isNull(), true, true);
if (app->sky.notNull()) { if (app->sky.notNull()) {
@@ -1439,16 +1316,11 @@ void Demo::onGraphics(RenderDevice* rd) {
app->renderDevice->setShadeMode(RenderDevice::SHADE_SMOOTH); app->renderDevice->setShadeMode(RenderDevice::SHADE_SMOOTH);
app->renderDevice->setAmbientLightColor(Color3(1,1,1)); app->renderDevice->setAmbientLightColor(Color3(1,1,1));
//Draw::axes(CoordinateFrame(Vector3(0, 0, 0)), app->renderDevice);
//makeFlag(Vector3(-1, 3.5, 0), rd);
//Vector3 vector = app->debugCamera.getCoordinateFrame().translation + app->debugCamera.getCoordinateFrame().lookVector()*20;
app->renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); app->renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
app->renderDevice->setAmbientLightColor(lighting.ambient); app->renderDevice->setAmbientLightColor(lighting.ambient);
//app->renderDevice->pushState();
//app->renderDevice->popState();
dataModel->getWorkspace()->render(rd); dataModel->getWorkspace()->render(rd);
if(selectedInstance != NULL) if(selectedInstance != NULL)
{ {
@@ -1457,40 +1329,18 @@ void Demo::onGraphics(RenderDevice* rd) {
Vector3 pos = part->getPosition(); Vector3 pos = part->getPosition();
drawOutline(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased()); drawOutline(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased());
} }
/*std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
for(size_t i = 0; i < instances.size(); i++)
{
Instance* instance = instances.at(i);
if(instance->getClassName() == "Part")
{
instance->render(rd);
PhysicalInstance* part = (PhysicalInstance*)instance;
//part->render(rd);
//Draw::box(part->getBox(), app->renderDevice, part->color, Color4::clear());
if(selectedInstance == part)
{
Vector3 size = part->getSize();
Vector3 pos = part->getCFrame().translation;
drawOutline(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased());
}
}
}
Box box;*/
//Draw::ray(testRay, rd, Color3::orange(), 1);
Vector3 gamepoint = Vector3(0, 5, 0); //Vector3 gamepoint = Vector3(0, 5, 0);
Vector3 camerapoint = rd->getCameraToWorldMatrix().translation; //Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5); //float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
if(distance < 50 && distance > -50) //if(distance < 50 && distance > -50)
{ //{
if(distance < 0) // if(distance < 0)
distance = distance*-1; // distance = distance*-1;
fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); // fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
} //}
app->renderDevice->disableLighting(); app->renderDevice->disableLighting();
@@ -1499,13 +1349,7 @@ void Demo::onGraphics(RenderDevice* rd) {
} }
app->renderDevice->push2D(); app->renderDevice->push2D();
//std::string str = ;
int offset = 25;
if(app->debugMode())
{
offset = 60;
}
if(System::time() - 3 < messageTime) if(System::time() - 3 < messageTime)
{ {
@@ -1514,39 +1358,21 @@ void Demo::onGraphics(RenderDevice* rd) {
std::stringstream stream; std::stringstream stream;
stream << std::fixed << std::setprecision(1) << dataModel->getWorkspace()->timer; stream << std::fixed << std::setprecision(1) << dataModel->getWorkspace()->timer;
fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 0+offset), 20, Color3::fromARGB(0x81C518), Color3::black()); fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black());
fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getWorkspace()->score), Vector2(rd->getWidth() - 120, 25+offset), 20, Color3::fromARGB(0x81C518), Color3::black()); fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getWorkspace()->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black());
//GUI Boxes //GUI Boxes
Draw::box(G3D::Box(Vector3(0,offset,0),Vector3(80,330+offset,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0)); Draw::box(G3D::Box(Vector3(0,25,0),Vector3(80,355,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));
//Draw::box(G3D::Box(Vector3(0,rd->getHeight() - 120,0),Vector3(80,rd->getHeight(),0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));
Draw::box(G3D::Box(Vector3(rd->getWidth() - 120,rd->getHeight() - 120,0),Vector3(rd->getWidth(),rd->getHeight(),0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0)); Draw::box(G3D::Box(Vector3(rd->getWidth() - 120,rd->getHeight() - 120,0),Vector3(rd->getWidth(),rd->getHeight(),0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));
//Camera menu title //Camera menu title
fntlighttrek->draw2D(rd, "CameraMenu", Vector2(rd->getWidth()-(fntlighttrek->get2DStringBounds("CameraMenu", 14).x+1),rd->getHeight() - 120), 14, Color3::white(), Color4(0.5F,0.5F,0.5F,0.5F)); fntlighttrek->draw2D(rd, "CameraMenu", Vector2(rd->getWidth()-(fntlighttrek->get2DStringBounds("CameraMenu", 14).x+1),rd->getHeight() - 120), 14, Color3::white(), Color4(0.5F,0.5F,0.5F,0.5F));
/*
fntlighttrek->draw2D(rd, "Model", Vector2(10,rd->getHeight() - (120 - spacing*0)), 12, Color3(0,255,255), Color4(0,0,0,0));
fntlighttrek->draw2D(rd, "Surface", Vector2(10,rd->getHeight() - (120 - spacing*1)), 12, Color3(0,255,255), Color4(0,0,0,0));
fntlighttrek->draw2D(rd, "Color", Vector2(10,rd->getHeight() - (120 - spacing*2)), 12, Color3(0,255,255), Color4(0,0,0,0));
fntlighttrek->draw2D(rd, "Controller", Vector2(10,rd->getHeight() - (120 - spacing*3)), 12, Color3(0,255,255), Color4(0,0,0,0));
fntlighttrek->draw2D(rd, "Hopper", Vector2(10,rd->getHeight() - (120 - spacing*4)), 12, Color3(0,255,255), Color4(0,0,0,0));
*/
//Tools menu //Tools menu
Draw::box(G3D::Box(Vector3(5, 185+offset,0),Vector3(75, 185+offset,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0.6F,0.6F,0.6F,0.4F)); Draw::box(G3D::Box(Vector3(5, 210,0),Vector3(75, 210,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0.6F,0.6F,0.6F,0.4F));
fntlighttrek->draw2D(rd,"MENU", Vector2(10,307+offset), 14, Color3::white(), Color4(0.5F,0.5F,0.5F,0.5F)); fntlighttrek->draw2D(rd,"MENU", Vector2(10,332), 14, Color3::white(), Color4(0.5F,0.5F,0.5F,0.5F));
//G3D::GFont::draw2D("Debug Mode Enabled", Vector2(0,30), 20, Color3::white(), Color3::black());
//app->debugFont->draw2D("Dynamica 2004-2005 Simulation Client version " + VERSION + str, Vector2(0,0), 20, Color3::white(), Color3::black());
//app->debugFont->draw2D("Debug Mode Enabled", Vector2(0,30), 20, Color3::white(), Color3::black());
drawButtons(rd); drawButtons(rd);
@@ -1615,12 +1441,6 @@ void App::main() {
applet->run(); applet->run();
} }
//App::App(const GAppSettings& settings, GWindow* wnd) : GApp(settings, wnd) {
// applet = new Demo(this);
//}
App::App(const GAppSettings& settings, GWindow* wnd,HWND tempMainHWnd, SDLWindow* wndSDL) : GApp(settings, wnd) { App::App(const GAppSettings& settings, GWindow* wnd,HWND tempMainHWnd, SDLWindow* wndSDL) : GApp(settings, wnd) {
applet = new Demo(this); applet = new Demo(this);
hwnd = wndSDL->win32HWND(); hwnd = wndSDL->win32HWND();
@@ -1651,9 +1471,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
HWND g3DWind = app->getHWND(); HWND g3DWind = app->getHWND();
app->applet->exitApplication(); app->applet->exitApplication();
//DestroyWindow(hwnd);
} }
//DestroyWindow(hwnd);
break; break;
case WM_DESTROY: case WM_DESTROY:
PostQuitMessage(0); PostQuitMessage(0);
@@ -1701,109 +1519,95 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
//_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
//_CrtSetBreakAlloc(1279);
try{ try{
tempPath = ((std::string)getenv("temp")) + "/Dynamica"; tempPath = ((std::string)getenv("temp")) + "/Dynamica";
CreateDirectory(tempPath.c_str(), NULL); CreateDirectory(tempPath.c_str(), NULL);
message = tempPath; message = tempPath;
messageTime = System::time(); messageTime = System::time();
AudioPlayer::init(); AudioPlayer::init();
GAppSettings settings; GAppSettings settings;
settings.window.resizable = true; settings.window.resizable = true;
//settings.window.fsaaSamples = 8; settings.writeLicenseFile = false;
settings.writeLicenseFile = false; settings.logFilename = tempPath + "/g3dlog.txt";
settings.logFilename = tempPath + "/g3dlog.txt"; settings.window.center = true;
settings.window.center = true; G3D::SDLWindow* wnd = new SDLWindow(settings.window);
//Using the damned SDL window now wnd->setMouseVisible(false);
G3D::SDLWindow* wnd = new SDLWindow(settings.window);
//wnd->setInputCaptureCount(200);
wnd->setMouseVisible(false);
WNDCLASSEX wc; WNDCLASSEX wc;
HINSTANCE hInstance = GetModuleHandle(NULL); HINSTANCE hInstance = GetModuleHandle(NULL);
wc.cbSize = sizeof(WNDCLASSEX); wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0; wc.style = 0;
wc.lpfnWndProc = WndProc; wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0; wc.cbClsExtra = 0;
wc.cbWndExtra = 0; wc.cbWndExtra = 0;
wc.hInstance = hInstance; wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL; wc.lpszMenuName = NULL;
wc.lpszClassName = "containerHWND"; wc.lpszClassName = "containerHWND";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx (&wc)) if (!RegisterClassEx (&wc))
return false; return false;
HMODULE hThisInstance = GetModuleHandle(NULL); HMODULE hThisInstance = GetModuleHandle(NULL);
HWND hwnd = wnd->win32HWND(); HWND hwnd = wnd->win32HWND();
HWND hwndMain = CreateWindowEx( HWND hwndMain = CreateWindowEx(
WS_EX_ACCEPTFILES | WS_EX_CLIENTEDGE, WS_EX_ACCEPTFILES | WS_EX_CLIENTEDGE,
"containerHWND", "containerHWND",
"Main test", "Main test",
WS_OVERLAPPEDWINDOW, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
800, 800,
600, 600,
NULL, // parent NULL, // parent
NULL, // menu NULL, // menu
hThisInstance, hThisInstance,
NULL NULL
); );
ShowWindow(hwndMain, SW_SHOW); ShowWindow(hwndMain, SW_SHOW);
if(hwndMain == NULL) if(hwndMain == NULL)
{ {
MessageBox(NULL, "Failed to create HWND","Dynamica Crash", MB_OK); MessageBox(NULL, "Failed to create HWND","Dynamica Crash", MB_OK);
return 0; return 0;
} }
SetParent(hwnd, hwndMain); SetParent(hwnd, hwndMain);
App app = App(settings, wnd, hwndMain, wnd); App app = App(settings, wnd, hwndMain, wnd);
RECT rect; RECT rect;
int width = 640; int width = 640;
int height = 480; int height = 480;
if(GetClientRect(hwndMain, &rect)) if(GetClientRect(hwndMain, &rect))
{ {
width = rect.right - rect.left; width = rect.right - rect.left;
height = rect.bottom - rect.top; height = rect.bottom - rect.top;
} }
SetWindowPos(hwnd, NULL, 0, 0, width, height, NULL); SetWindowPos(hwnd, NULL, 0, 0, width, height, NULL);
LONG lStyle = GetWindowLong(hwnd, GWL_STYLE); LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU); lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
SetWindowLong(hwnd, GWL_STYLE, lStyle); SetWindowLong(hwnd, GWL_STYLE, lStyle);
LONG lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE); LONG lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE); lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
SetWindowLong(hwnd, GWL_EXSTYLE, lExStyle); SetWindowLong(hwnd, GWL_EXSTYLE, lExStyle);
SetWindowLongPtr(hwndMain, GWL_USERDATA, (LONG)&app);
//SetWindowLong(hwnd, GWL_STYLE, WS_VISIBLE | WS_CHILD); HICON hicon = (HICON)LoadImage(GetModuleHandleW(NULL), (LPCSTR)MAKEINTRESOURCEW(IDI_ICON1), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
SetWindowLongPtr(hwndMain, GWL_USERDATA, (LONG)&app); SendMessage(hwndMain, WM_SETICON, ICON_BIG, (LPARAM)hicon);
HICON hicon = (HICON)LoadImage(GetModuleHandleW(NULL), (LPCSTR)MAKEINTRESOURCEW(IDI_ICON1), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE); SetWindowPos(hwndMain, NULL, 0, 0, 800, 600, NULL);
SendMessage(hwndMain, WM_SETICON, ICON_BIG, (LPARAM)hicon);
if(GetClientRect(hwndMain, &rect))
{
SetWindowPos(hwndMain, NULL, 0, 0, 800, 600, NULL); width = rect.right - rect.left;
height = rect.bottom - rect.top;
}
if(GetClientRect(hwndMain, &rect)) SetWindowPos(hwnd, NULL, 0, 0, width, height, NULL);
{ app.run();
width = rect.right - rect.left;
height = rect.bottom - rect.top;
}
SetWindowPos(hwnd, NULL, 0, 0, width, height, NULL);
//message = Convert(widthMON) + ", " + Convert(heightMON);
//messageTime = G3D::System::time();
app.run();
} }
catch(...) catch(...)
{ {