bool StartMe::OnInitialize(int /*argc*/, char* /*argv*/ []) { if (!csInitializer::SetupConfigManager (GetObjectRegistry (), "/config/startme.cfg")) return ReportError ("Error reading config file %s!", CS::Quote::Single ("startme.cfg")); // RequestPlugins() will load all plugins we specify. In addition // it will also check if there are plugins that need to be loaded // from the config system (both the application config and CS or // global configs). In addition it also supports specifying plugins // on the commandline. if (!csInitializer::RequestPlugins(GetObjectRegistry(), CS_REQUEST_VFS, CS_REQUEST_OPENGL3D, CS_REQUEST_ENGINE, CS_REQUEST_FONTSERVER, CS_REQUEST_IMAGELOADER, CS_REQUEST_LEVELLOADER, CS_REQUEST_REPORTER, CS_REQUEST_REPORTERLISTENER, CS_REQUEST_PLUGIN ("crystalspace.cegui.wrapper", iCEGUI), CS_REQUEST_END)) return ReportError ("Failed to initialize plugins!"); csBaseEventHandler::Initialize(GetObjectRegistry()); // Now we need to setup an event handler for our application. // Crystal Space is fully event-driven. Everything (except for this // initialization) happens in an event. if (!RegisterQueue (GetObjectRegistry(), csevAllEvents(GetObjectRegistry()))) return ReportError ("Failed to set up event handler!"); return true; }
bool StartMe::OnLogoClicked (const CEGUI::EventArgs& e) { csRef<iEventQueue> q = csQueryRegistry<iEventQueue> (GetObjectRegistry()); if (q.IsValid()) q->GetEventOutlet()->Broadcast(csevQuit(GetObjectRegistry())); return true; }
bool AppWaterdemo2::Application() { iObjectRegistry* r = GetObjectRegistry(); // Open the main system. This will open all the previously loaded plugins // (i.e. all windows will be opened). if (!OpenApplication(r)) return ReportError("Error opening system!"); // Now get the pointer to various modules we need. We fetch them from the // object registry. The RequestPlugins() call we did earlier registered all // loaded plugins with the object registry. It is also possible to load // plugins manually on-demand. g3d = csQueryRegistry<iGraphics3D> (r); if (!g3d) return ReportError("Failed to locate 3D renderer!"); engine = csQueryRegistry<iEngine> (r); if (!engine) return ReportError("Failed to locate 3D engine!"); vc = csQueryRegistry<iVirtualClock> (r); if (!vc) return ReportError("Failed to locate Virtual Clock!"); kbd = csQueryRegistry<iKeyboardDriver> (r); if (!kbd) return ReportError("Failed to locate Keyboard Driver!"); loader = csQueryRegistry<iLoader> (r); if (!loader) return ReportError("Failed to locate Loader!"); rotY = 0; rotX = 0; if(!LoadMap()) return 0; room = engine->FindSector ("room"); engine->Prepare (); view.AttachNew(new csView (engine, g3d)); iGraphics2D* g2d = g3d->GetDriver2D (); view->SetRectangle (0, 0, g2d->GetWidth (), g2d->GetHeight ()); view->GetCamera ()->SetSector (room); view->GetCamera ()->GetTransform ().SetOrigin (csVector3 (0, 3, 0)); printer.AttachNew (new FramePrinter (GetObjectRegistry ())); //****************** END OF INITIALIZATION STUFFS ***********************// // Start the default run/event loop. This will return only when some code, // such as OnKeyboard(), has asked the run loop to terminate. Run(); return true; }
void Simple::CreateRoom () { // We create a new sector called "room". room = engine->CreateSector ("room"); // Create our world. ReportInfo ("Creating world!..."); loader->LoadTexture ("stone", "/lib/std/stone4.gif"); csRef<iPluginManager> plugin_mgr ( csQueryRegistry<iPluginManager> (GetObjectRegistry())); // Initialize the python plugin. csRef<iScript> is = csQueryRegistry<iScript> (GetObjectRegistry()); if (is) { char const* module = "pysimp"; csRef<iCommandLineParser> cmd = csQueryRegistry<iCommandLineParser> (GetObjectRegistry()); if (cmd.IsValid()) { char const* file = cmd->GetName(0); if (file != 0) module = file; } // Load a python module. ReportInfo ("Loading script file %s...", CS::Quote::Single (module)); if (!is->LoadModule (module)) return; // Set up our room. // Execute one method defined in pysimp.py // This will create the polygons in the room. csString run; run << module << ".CreateRoom"; // prepare arguments csRefArray<iScriptValue> args; args.Push(csRef<iScriptValue>(is->RValue("stone"))); // run method csRef<iScriptValue> ret = is->Call(run,args); if(!ret.IsValid()) { ReportError ("Failed running '%s.CreateRoom'...",module); } } else ReportError ("Could not load Python plugin"); csRef<iLight> light; light = engine->CreateLight (0, csVector3 (0, 5, 0), 10, csColor (1, 0, 0)); room->GetLights ()->Add (light); }
void AvatarTest::CreateRoom () { // Creating the background // First we make a primitive for our geometry. CS::Geometry::DensityTextureMapper bgMapper (0.3f); CS::Geometry::TesselatedBox bgBox (csVector3 (-4000), csVector3 (4000)); bgBox.SetMapper (&bgMapper); bgBox.SetFlags (CS::Geometry::Primitives::CS_PRIMBOX_INSIDE); // Now we make a factory and a mesh at once. csRef<iMeshWrapper> background = CS::Geometry::GeneralMeshBuilder::CreateFactoryAndMesh (engine, room, "background", "background_factory", &bgBox); csRef<iMaterialWrapper> bgMaterial = CS::Material::MaterialBuilder::CreateColorMaterial (GetObjectRegistry (), "background", csColor (0.398f)); background->GetMeshObject()->SetMaterialWrapper (bgMaterial); // Set up of the physical collider for the roof if (physicsEnabled) dynamicSystem->AttachColliderPlane (csPlane3 (csVector3 (0.0f, 1.0f, 0.0f), 0.0f), 10.0f, 0.0f); // Creating lights csRef<iLight> light; iLightList* ll = room->GetLights (); // This light is for the background // TODO: putting instead the following line creates a black background, otherwise it is grey // the behavior doesn't persist if the other lights are removed //light = engine->CreateLight(0, csVector3(1, 1, -1), 9000, csColor (1)); light = engine->CreateLight(0, csVector3(1, 1, 0), 9000, csColor (1)); light->SetAttenuationMode (CS_ATTN_NONE); ll->Add (light); // Other lights light = engine->CreateLight (0, csVector3 (3, 0, 0), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); light = engine->CreateLight (0, csVector3 (-3, 0, 0), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); light = engine->CreateLight (0, csVector3 (0, 0, -3), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); light = engine->CreateLight (0, csVector3 (0, 0, 3), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); light = engine->CreateLight (0, csVector3 (0, -3, 0), 8, csColor (1)); light->SetAttenuationMode (CS_ATTN_REALISTIC); ll->Add (light); engine->Prepare (); CS::Lighting::SimpleStaticLighter::ShineLights (room, engine, 4); }
bool SelfShadowDemo::Application () { // Default behavior from DemoApplication if (!DemoApplication::Application ()) return false; // Add keys descriptions hudManager->GetKeyDescriptions()->Push ("w a s d keys: rotate light"); hudManager->GetKeyDescriptions()->Push ("r: recompute splitting function"); hudManager->GetKeyDescriptions()->Push ("t: show render textures"); hudManager->GetKeyDescriptions()->Push ("g: dynamic grass"); hudManager->GetKeyDescriptions()->Push ("n: next scene"); hudManager->GetKeyDescriptions()->Push ("p: previous scene"); /* NOTE: Config settings for render managers are stored in 'engine.cfg' * and are needed when loading a render manager. Normally these settings * are added by the engine when it loads a render manager. However, since * we are loading the shadow_pssm render manager manually we must also manually * add the proper config file. */ csRef<iConfigManager> cfg = csQueryRegistry<iConfigManager> (GetObjectRegistry()); cfg->AddDomain ("/config/engine.cfg", vfs, iConfigManager::ConfigPriorityPlugin); csRef<iRenderManager> rm = csLoadPlugin<iRenderManager> (GetObjectRegistry(), "crystalspace.rendermanager.osm"); if (!rm) return ReportError("Failed to load OSM Render Manager!"); // Load debuger for changing various settings rm_dbg = scfQueryInterface<iDebugHelper>(rm); sceneNumber = 5; rotateGrass = false; cfg->RemoveDomain ("/config/engine.cfg"); engine->SetRenderManager(rm); // Create the scene if (!CreateScene ()) return false; // Run the application Run(); return true; }
void IslandDemo::PrintHelp () { csCommandLineHelper commandLineHelper; // Printing help commandLineHelper.PrintApplicationHelp (GetObjectRegistry (), "csisland", "csisland", "Crystal Space's island environment demo."); }
void SelfShadowDemo::PrintHelp () { csCommandLineHelper commandLineHelper; // Printing help commandLineHelper.PrintApplicationHelp (GetObjectRegistry (), "selfshadowdemo", "selfshadowdemo", "Crystal Space's self shadow RM demo."); }
bool EventTest::OnInitialize(int /*argc*/, char* /*argv*/ []) { // RequestPlugins() will load all plugins we specify. In addition // it will also check if there are plugins that need to be loaded // from the config system (both the application config and CS or // global configs). In addition it also supports specifying plugins // on the commandline. if (!csInitializer::RequestPlugins(GetObjectRegistry(), CS_REQUEST_VFS, CS_REQUEST_OPENGL3D, CS_REQUEST_FONTSERVER, CS_REQUEST_END)) return ReportError("Failed to initialize plugins!"); // Attempt to load a joystick plugin. csRef<iStringArray> joystickClasses = iSCF::SCF->QueryClassList ("crystalspace.device.joystick."); if (joystickClasses.IsValid()) { csRef<iPluginManager> plugmgr = csQueryRegistry<iPluginManager> (object_reg); for (size_t i = 0; i < joystickClasses->GetSize (); i++) { const char* className = joystickClasses->Get (i); csRef<iBase> b = plugmgr->LoadPlugin (className); csReport (object_reg, CS_REPORTER_SEVERITY_NOTIFY, "crystalspace.application.joytest", "Attempt to load plugin '%s' %s", className, (b != 0) ? "successful" : "failed"); if (b != 0) b->DecRef (); } } // "Warm up" the event handler so it can interact with the world csBaseEventHandler::Initialize(GetObjectRegistry()); // Now we need to register the event handler for our application. // Crystal Space is fully event-driven. Everything (except for this // initialization) happens in an event. if (!RegisterQueue(GetObjectRegistry(), csevAllEvents(GetObjectRegistry()))) return ReportError("Failed to set up event handler!"); return true; }
bool AvatarTest::OnKeyboard (iEvent &ev) { csKeyEventType eventtype = csKeyEventHelper::GetEventType(&ev); if (eventtype == csKeyEventTypeDown) { // Check for ESC key if (csKeyEventHelper::GetCookedCode (&ev) == CSKEY_ESC) { csRef<iEventQueue> q (csQueryRegistry<iEventQueue> (GetObjectRegistry ())); if (q) q->GetEventOutlet()->Broadcast (csevQuit (GetObjectRegistry ())); return true; } // Check for switching of model else if (csKeyEventHelper::GetCookedCode (&ev) == 'm') { if (avatarModel == MODEL_FRANKIE) { avatarModel = MODEL_KRYSTAL; delete avatarScene; avatarScene = new KrystalScene (this); } else { avatarModel = MODEL_FRANKIE; delete avatarScene; avatarScene = new FrankieScene (this); } if (!avatarScene->CreateAvatar ()) { printf ("Problem loading model. Exiting.\n"); csRef<iEventQueue> q (csQueryRegistry<iEventQueue> (GetObjectRegistry ())); if (q) q->GetEventOutlet()->Broadcast (csevQuit (GetObjectRegistry ())); return true; } return true; } } return avatarScene->OnKeyboard (ev); }
bool AppWaterdemo2::LoadMap () { // Set VFS current directory to the level we want to load. csRef<iVFS> VFS (csQueryRegistry<iVFS> (GetObjectRegistry ())); VFS->ChDir ("/lev/oceantest"); // Load the level file which is called 'world'. if (!loader->LoadMapFile ("world")) ReportError("Error couldn't load level!"); return true; }
bool EventTest::Application() { // Open the main system. This will open all the previously loaded plug-ins. // i.e. all windows will be opened. if (!OpenApplication(GetObjectRegistry())) return ReportError("Error opening system!"); Run(); return true; }
bool Simple::OnInitialize(int /*argc*/, char* /*argv*/ []) { // RequestPlugins() will load all plugins we specify. In addition // it will also check if there are plugins that need to be loaded // from the config system (both the application config and CS or // global configs). In addition it also supports specifying plugins // on the commandline. if (!csInitializer::RequestPlugins(GetObjectRegistry(), CS_REQUEST_VFS, CS_REQUEST_OPENGL3D, CS_REQUEST_ENGINE, CS_REQUEST_FONTSERVER, CS_REQUEST_IMAGELOADER, CS_REQUEST_LEVELLOADER, CS_REQUEST_REPORTER, CS_REQUEST_REPORTERLISTENER, CS_REQUEST_PLUGIN( "crystalspace.script.python", iScript ), CS_REQUEST_END)) return ReportError("Failed to initialize plugins!"); // "Warm up" the event handler so it can interact with the world csBaseEventHandler::Initialize(GetObjectRegistry()); // Now we need to register the event handler for our application. // Crystal Space is fully event-driven. Everything (except for this // initialization) happens in an event. // Rather than simply handling all events, we subscribe to the // particular events we're interested in. csEventID events[] = { csevFrame (GetObjectRegistry()), csevKeyboardEvent (GetObjectRegistry()), CS_EVENTLIST_END }; if (!RegisterQueue(GetObjectRegistry(), events)) return ReportError("Failed to set up event handler!"); // Report success return true; }
bool AppWaterdemo2::OnInitialize(int argc, char* argv[]) { iObjectRegistry* r = GetObjectRegistry(); // Load application-specific configuration file. // if (!csInitializer::SetupConfigManager(r, // "/my/vfs/path/AppWaterdemo2.cfg", GetApplicationName())) // return ReportError("Failed to initialize configuration manager!"); // RequestPlugins() will load all plugins we specify. In addition it will // also check if there are plugins that need to be loaded from the // configuration system (both the application configuration and CS or global // configurations). It also supports specifying plugins on the command line // via the --plugin= option. if (!csInitializer::RequestPlugins(r, CS_REQUEST_VFS, CS_REQUEST_OPENGL3D, CS_REQUEST_ENGINE, CS_REQUEST_FONTSERVER, CS_REQUEST_IMAGELOADER, CS_REQUEST_LEVELLOADER, CS_REQUEST_REPORTER, CS_REQUEST_REPORTERLISTENER, CS_REQUEST_CONSOLEOUT, CS_REQUEST_END)) return ReportError("Failed to initialize plugins!"); // "Warm up" the event handler so it can interact with the world csBaseEventHandler::Initialize(GetObjectRegistry()); // Set up an event handler for the application. Crystal Space is fully // event-driven. Everything (except for this initialization) happens in // response to an event. if (!RegisterQueue (r, csevAllEvents(GetObjectRegistry()))) return ReportError("Failed to set up event handler!"); return true; }
bool StartMe::OnKeyboard(iEvent& ev) { // We got a keyboard event. csKeyEventType eventtype = csKeyEventHelper::GetEventType(&ev); if (eventtype == csKeyEventTypeDown) { // The user pressed a key (as opposed to releasing it). utf32_char code = csKeyEventHelper::GetCookedCode(&ev); if (code == CSKEY_ESC) { // The user pressed escape to exit the application. // The proper way to quit a Crystal Space application // is by broadcasting a csevQuit event. That will cause the // main runloop to stop. To do that we get the event queue from // the object registry and then post the event. csRef<iEventQueue> q = csQueryRegistry<iEventQueue> (GetObjectRegistry()); if (q.IsValid()) q->GetEventOutlet()->Broadcast(csevQuit(GetObjectRegistry())); } } return false; }
bool SelfShadowDemo::OnInitialize (int argc, char* argv[]) { // Default behavior from csDemoApplication if (!DemoApplication::OnInitialize (argc, argv)) return false; // Load furmesh for krystal scene if (!csInitializer::RequestPlugins (GetObjectRegistry (), CS_REQUEST_PLUGIN("crystalspace.mesh.object.furmesh", CS::Mesh::iFurMeshType), CS_REQUEST_END)) return ReportError ("Failed to initialize plugins!"); return true; }
bool Simple::Application() { // Open the main system. This will open all the previously loaded plug-ins. // i.e. all windows will be opened. if (!OpenApplication(GetObjectRegistry())) return ReportError("Error opening system!"); if (SetupModules()) { // This calls the default runloop. This will basically just keep // broadcasting process events to keep the game going. Run(); } return true; }
bool StartMe::OnMouseMove (iEvent& ev) { if (rotationStatus == OVER_EXIT) return false; // Compute the angle and distance to the bottom right corner of the window csRef<iGraphics2D> g2d = csQueryRegistry<iGraphics2D> (GetObjectRegistry ()); float x = g2d->GetWidth () - csMouseEventHelper::GetX(&ev) - 104.0f; float y = g2d->GetHeight () - csMouseEventHelper::GetY(&ev) + 4.0f; float distance = csQsqrt (x * x + y * y); float angle = atan2 (y - 4.0f, x + 104.0f); float angleDistance = 1.0f - fabs (PI * 0.27f - angle) / (PI * 0.25f); distance -= angleDistance * 50.0f; // If the mouse is too far away then rotate at default speed if (distance < 170.0f || distance > 380.0f) { rotationStatus = ROTATE_NORMAL; rotationSpeed = DEFAULT_ROTATION_SPEED; return false; } // If the mouse is near the center then stop the rotation if (angle > PI * 0.166f && angle < PI * 0.333f) rotationStatus = ROTATE_SELECTING; // If the mouse is on the side, then rotate faster else { rotationStatus = ROTATE_SEARCHING; if (angle > PI * 0.333f) { float distance = angle - PI * 0.333f; rotationSpeed = - DEFAULT_ROTATION_SPEED * distance * 15.0f; } else { float distance = PI * 0.166f - angle; rotationSpeed = DEFAULT_ROTATION_SPEED * distance * 15.0f; } } return false; }
bool Simple::SetupModules () { // Now get the pointer to various modules we need. We fetch them // from the object registry. The RequestPlugins() call we did earlier // registered all loaded plugins with the object registry. g3d = csQueryRegistry<iGraphics3D> (GetObjectRegistry()); if (!g3d) return ReportError("Failed to locate 3D renderer!"); engine = csQueryRegistry<iEngine> (GetObjectRegistry()); if (!engine) return ReportError("Failed to locate 3D engine!"); vc = csQueryRegistry<iVirtualClock> (GetObjectRegistry()); if (!vc) return ReportError("Failed to locate Virtual Clock!"); kbd = csQueryRegistry<iKeyboardDriver> (GetObjectRegistry()); if (!kbd) return ReportError("Failed to locate Keyboard Driver!"); loader = csQueryRegistry<iLoader> (GetObjectRegistry()); if (!loader) return ReportError("Failed to locate Loader!"); // We need a View to the virtual world. view.AttachNew(new csView (engine, g3d)); iGraphics2D* g2d = g3d->GetDriver2D (); // We use the full window to draw the world. view->SetRectangle (0, 0, g2d->GetWidth (), g2d->GetHeight ()); // Here we create our world. CreateRoom(); // Let the engine prepare all lightmaps for use and also free all images // that were loaded for the texture manager. engine->Prepare (); rm = engine->GetRenderManager(); // these are used store the current orientation of the camera rotY = rotX = 0; // Now we need to position the camera in our world. view->GetCamera ()->SetSector (room); view->GetCamera ()->GetTransform ().SetOrigin (csVector3 (0, 5, -3)); // We use some other "helper" event handlers to handle // pushing our work into the 3D engine and rendering it // to the screen. //drawer.AttachNew(new FrameBegin3DDraw (GetObjectRegistry (), view)); printer.AttachNew(new FramePrinter (GetObjectRegistry ())); return true; }
bool StartMe::OnClick (const CEGUI::EventArgs& e) { // TODO: don't relaunch if it was multi clicked if (rotationStatus != ROTATE_SELECTING) return true; const CEGUI::WindowEventArgs& args = static_cast<const CEGUI::WindowEventArgs&>(e); for (size_t i = 0 ; i < demos.GetSize () ; i++) if (demos[i].window == args.window) { csRef<iCommandLineParser> cmdline = csQueryRegistry<iCommandLineParser> (GetObjectRegistry()); csString appdir = cmdline->GetAppDir (); if (system (csString("\"") << appdir << CS_PATH_SEPARATOR << csInstallationPathsHelper::GetAppFilename ( demos[i].exec) << "\" " << demos[i].args)) break; else break; } return true; }
bool AppWaterdemo2::OnKeyboard(iEvent& ev) { // We got a keyboard event. if (csKeyEventHelper::GetEventType(&ev) == csKeyEventTypeDown) { // The user pressed a key (as opposed to releasing it). utf32_char code = csKeyEventHelper::GetCookedCode(&ev); if (code == CSKEY_ESC) { // The user pressed escape, so terminate the application. The proper way // to terminate a Crystal Space application is by broadcasting a // csevQuit event. That will cause the main run loop to stop. To do // so we retrieve the event queue from the object registry and then post // the event. csRef<iEventQueue> q = csQueryRegistry<iEventQueue> (GetObjectRegistry()); if (q.IsValid()) // q->GetEventOutlet()->Broadcast(csevQuit(GetObjectRegistry())); exit(0); // HACK TO AVOID SEGFAULT ON EXIT } } return false; }
bool AvatarTest::Application () { if (!OpenApplication (GetObjectRegistry ())) return ReportError ("Error opening system!"); g3d = csQueryRegistry<iGraphics3D> (GetObjectRegistry ()); if (!g3d) return ReportError("Failed to locate 3D renderer!"); engine = csQueryRegistry<iEngine> (GetObjectRegistry ()); if (!engine) return ReportError("Failed to locate 3D engine!"); vc = csQueryRegistry<iVirtualClock> (GetObjectRegistry ()); if (!vc) return ReportError("Failed to locate Virtual Clock!"); kbd = csQueryRegistry<iKeyboardDriver> (GetObjectRegistry ()); if (!kbd) return ReportError("Failed to locate Keyboard Driver!"); loader = csQueryRegistry<iLoader> (GetObjectRegistry ()); if (!loader) return ReportError("Failed to locate Loader!"); g2d = csQueryRegistry<iGraphics2D> (GetObjectRegistry ()); if (!g2d) return ReportError("Failed to locate 2D renderer!"); lookAtManager = csQueryRegistry<iSkeletonLookAtManager2> (GetObjectRegistry ()); if (!lookAtManager) return ReportError("Failed to locate iLookAtManager plugin!"); basicNodesManager = csQueryRegistry<iSkeletonBasicNodesManager2> (GetObjectRegistry ()); if (!basicNodesManager) return ReportError("Failed to locate iSkeletonBasicNodesManager2 plugin!"); printer.AttachNew (new FramePrinter (GetObjectRegistry ())); csRef<iFontServer> fs = g3d->GetDriver2D()->GetFontServer (); if (fs) courierFont = fs->LoadFont (CSFONT_COURIER); else return ReportError ("Failed to locate font server!"); // Create the dynamic system if (physicsEnabled) { dynamicSystem = dynamics->CreateSystem (); if (!dynamicSystem) { ReportWarning ("Can't create dynamic system, continuing with reduced functionalities"); physicsEnabled = false; } else { // Load the ragdoll plugin csRef<iPluginManager> plugmgr = csQueryRegistry<iPluginManager> (GetObjectRegistry ()); ragdollManager = csLoadPlugin<iSkeletonRagdollManager2> (plugmgr, "crystalspace.mesh.animesh.controllers.ragdoll"); if (!ragdollManager) { ReportWarning ("Can't load ragdoll plugin, continuing with reduced functionalities"); physicsEnabled = false; } } } // Create sector room = engine->CreateSector ("room"); // Initialize camera view = csPtr<iView> (new csView (engine, g3d)); view->GetCamera ()->SetSector (room); iGraphics2D* g2d = g3d->GetDriver2D (); view->SetRectangle (0, 0, g2d->GetWidth (), g2d->GetHeight ()); // Create scene CreateRoom (); // Create avatar if (avatarModel == MODEL_KRYSTAL) avatarScene = new KrystalScene (this); else avatarScene = new FrankieScene (this); if (!avatarScene->CreateAvatar ()) return false; // Initialize camera position view->GetCamera ()->GetTransform ().SetOrigin (avatarScene->GetCameraStart ()); // Run the application Run(); return true; }
bool StartMe::Application() { // Set up window transparency. Must happen _before_ system is opened! csRef<iGraphics2D> g2d = csQueryRegistry<iGraphics2D> (GetObjectRegistry ()); if (!g2d) return ReportError ("Failed to obtain canvas!"); natwin = scfQueryInterface<iNativeWindow> (g2d); if (natwin) { natwin->SetWindowTransparent (true); } // Open the main system. This will open all the previously loaded plug-ins. // i.e. all windows will be opened. if (!OpenApplication(GetObjectRegistry())) return ReportError("Error opening system!"); // The window is open, so lets make it disappear! if (natwin) { natwin->SetWindowDecoration (iNativeWindow::decoCaption, false); natwin->SetWindowDecoration (iNativeWindow::decoClientFrame, false); } // Now get the pointer to various modules we need. We fetch them // from the object registry. The RequestPlugins() call we did earlier // registered all loaded plugins with the object registry. g3d = csQueryRegistry<iGraphics3D> (GetObjectRegistry()); if (!g3d) return ReportError("Failed to locate 3D renderer!"); engine = csQueryRegistry<iEngine> (GetObjectRegistry()); if (!engine) return ReportError("Failed to locate 3D engine!"); vc = csQueryRegistry<iVirtualClock> (GetObjectRegistry()); if (!vc) return ReportError("Failed to locate Virtual Clock!"); kbd = csQueryRegistry<iKeyboardDriver> (GetObjectRegistry()); if (!kbd) return ReportError("Failed to locate Keyboard Driver!"); loader = csQueryRegistry<iLoader> (GetObjectRegistry()); if (!loader) return ReportError("Failed to locate Loader!"); vfs = csQueryRegistry<iVFS> (GetObjectRegistry()); if (!vfs) return ReportError("Failed to locate VFS!"); confman = csQueryRegistry<iConfigManager> (GetObjectRegistry()); if (!confman) return ReportError("Failed to locate Config Manager!"); cegui = csQueryRegistry<iCEGUI> (GetObjectRegistry()); if (!cegui) return ReportError("Failed to locate CEGUI plugin"); // Initialize the CEGUI wrapper cegui->Initialize (); // Let the CEGUI plugin take care of the rendering by itself cegui->SetAutoRender (true); // Set the logging level cegui->GetLoggerPtr ()->setLoggingLevel(CEGUI::Informative); vfs->ChDir ("/cegui/"); // Load the 'ice' skin (which uses the Falagard skinning system) cegui->GetSchemeManagerPtr ()->create("ice.scheme"); cegui->GetSystemPtr ()->setDefaultMouseCursor("ice", "MouseArrow"); // Setup the fonts cegui->GetFontManagerPtr ()->createFreeTypeFont (FONT_NORMAL, 10, true, "/fonts/ttf/DejaVuSerif.ttf"); cegui->GetFontManagerPtr ()->createFreeTypeFont (FONT_NORMAL_ITALIC, 10, true, "/fonts/ttf/DejaVuSerif-Italic.ttf"); cegui->GetFontManagerPtr ()->createFreeTypeFont (FONT_TITLE, 15, true, "/fonts/ttf/DejaVuSerif-Bold.ttf"); cegui->GetFontManagerPtr ()->createFreeTypeFont (FONT_TITLE_ITALIC, 15, true, "/fonts/ttf/DejaVuSerif-BoldItalic.ttf"); CEGUI::WindowManager* winMgr = cegui->GetWindowManagerPtr (); // Load the CEGUI layout and set it as the root layout vfs->ChDir ("/data/startme/"); cegui->GetSchemeManagerPtr ()->create ("crystal.scheme"); cegui->GetSystemPtr ()->setGUISheet(winMgr->loadWindowLayout ("startme.layout")); // We need a View to the virtual world. view.AttachNew (new csView (engine, g3d)); LoadConfig (); CEGUI::Window* logo = winMgr->getWindow("Logo"); logo->subscribeEvent(CEGUI::Window::EventMouseClick, CEGUI::Event::Subscriber(&StartMe::OnLogoClicked, this)); ///TODO: Using 'EventMouseEntersArea' is more correct but is only available /// in 0.7.2+ logo->subscribeEvent(CEGUI::Window::EventMouseEnters, CEGUI::Event::Subscriber(&StartMe::OnEnterLogo, this)); logo->subscribeEvent(CEGUI::Window::EventMouseLeaves, CEGUI::Event::Subscriber(&StartMe::OnLeaveLogo, this)); vfs->ChDir ("/lib/startme"); CEGUI::Window* root = winMgr->getWindow("root"); for (size_t i = 0 ; i < demos.GetSize () ; i++) { demos[i].window = winMgr->createWindow("crystal/Icon"); demos[i].window->setSize(CEGUI::UVector2(CEGUI::UDim(0.0f, 128.0f), CEGUI::UDim(0.0f, 128.0f))); demos[i].window->setPosition(CEGUI::UVector2(CEGUI::UDim(0.0f, 0.0f), CEGUI::UDim(0.0f, 0.0f))); demos[i].window->setVisible(false); CEGUI::ImagesetManager* imsetmgr = cegui->GetImagesetManagerPtr(); if (!imsetmgr->isDefined(demos[i].image)) imsetmgr->createFromImageFile(demos[i].image, demos[i].image); std::string img = "set:"+std::string(demos[i].image)+" image:full_image"; demos[i].window->setProperty("Image", img); root->addChildWindow(demos[i].window); demos[i].window->subscribeEvent(CEGUI::Window::EventMouseClick, CEGUI::Event::Subscriber(&StartMe::OnClick, this)); } // Initialize the starting position of the demo wheel to a random value csRandomFloatGen frandomGenerator; position = frandomGenerator.Get (demos.GetSize () - 1); // Let the engine prepare everything engine->Prepare (); printer.AttachNew (new FramePrinter (object_reg)); // This calls the default runloop. This will basically just keep // broadcasting process events to keep the application going on. Run(); return true; }
bool EventTest::HandleEvent (iEvent &ev) { csRef<iEventNameRegistry> namereg = csEventNameRegistry::GetRegistry ( GetObjectRegistry ()); if (CS_IS_KEYBOARD_EVENT (namereg, ev)) { utf32_char key = csKeyEventHelper::GetRawCode (&ev); utf32_char cooked = csKeyEventHelper::GetCookedCode (&ev); bool autorep = csKeyEventHelper::GetAutoRepeat (&ev); csKeyModifiers key_modifiers; csKeyEventHelper::GetModifiers (&ev, key_modifiers); uint32 modifiers = csKeyEventHelper::GetModifiersBits (key_modifiers); uint32 type = csKeyEventHelper::GetEventType (&ev); csString str = csInputDefinition::GetKeyString (namereg, key, &key_modifiers, true); printf ("Key %s: raw=%" PRId32 "(%c) " "cooked=%" PRId32 "(%c) rep=%d mods=%08" PRIu32 " desc='%s'\n", type == csKeyEventTypeUp ? "UP" : "DO", key, (key >= 32 && key < 128) ? (char)key : '-', cooked, (cooked >= 32 && cooked < 128) ? (char)cooked : '-', autorep, modifiers, str.GetData ()); fflush (stdout); } else if (CS_IS_MOUSE_EVENT (namereg, ev)) { uint device = csMouseEventHelper::GetNumber (&ev); csMouseEventType type = csMouseEventHelper::GetEventType (&ev); csKeyModifiers key_modifiers; csKeyEventHelper::GetModifiers (&ev, key_modifiers); uint32 modifiers = csMouseEventHelper::GetModifiers (&ev); csMouseEventData data; csMouseEventHelper::GetEventData (&ev, data); int x = csMouseEventHelper::GetX (&ev); int y = csMouseEventHelper::GetY (&ev); uint but = csMouseEventHelper::GetButton (&ev); bool butstate = csMouseEventHelper::GetButtonState (&ev); uint32 butmask = csMouseEventHelper::GetButtonMask (&ev); csInputDefinition def (namereg, &ev, modifiers, true); //do we want cooked? csString str = def.ToString (); printf ("Mouse %s: but=%d(state=%d,mask=%08" PRIu32 ") " "device=%d x=%d y=%d mods=%08" PRIu32 " desc='%s'\n", type == csMouseEventTypeMove ? "MOVE" : type == csMouseEventTypeUp ? "UP" : type == csMouseEventTypeDown ? "DO" : type == csMouseEventTypeClick ? "CLICK" : type == csMouseEventTypeDoubleClick ? "DBL" : "?", but, butstate, butmask, device, x, y, modifiers, str.GetData ()); fflush (stdout); } else if (CS_IS_JOYSTICK_EVENT (namereg, ev)) { uint device = csJoystickEventHelper::GetNumber (&ev); csKeyModifiers key_modifiers; csKeyEventHelper::GetModifiers (&ev, key_modifiers); uint32 modifiers = csJoystickEventHelper::GetModifiers (&ev); csJoystickEventData data; csJoystickEventHelper::GetEventData (&ev, data); csInputDefinition def (namereg, &ev, modifiers, true); csString str = def.ToString (false); csString desc (""); if (CS_IS_JOYSTICK_BUTTON_EVENT (namereg, ev, device)) { uint but = csJoystickEventHelper::GetButton (&ev); bool butstate = csJoystickEventHelper::GetButtonState (&ev); uint32 butmask = csJoystickEventHelper::GetButtonMask (&ev); printf ("Joystick %s: device=%d but=%d(state=%d,mask=%08" PRIu32 ") " "mods=%08" PRIu32 " desc='%s'\n", butstate ? "DO" : "UP", device, but, butstate, butmask, modifiers, str.GetData ()); } else if (CS_IS_JOYSTICK_MOVE_EVENT (namereg, ev, device)) { size_t pos = str.Find ("Axis"); str.SubString (desc, pos + 4, (size_t)-1); uint axisnum = atoi(desc.GetData ()); printf ("Joystick MOVE: device=%d axis=%" PRId32 " value=%d " "mods=%08" PRIu32 " desc='%s'\n", device, axisnum, data.axes[axisnum], modifiers, str.GetData ()); } fflush(stdout); } csBaseEventHandler::HandleEvent(ev); return false; }
bool AvatarTest::OnInitialize (int /*argc*/, char* /*argv*/ []) { // Check for commandline help. if (csCommandLineHelper::CheckHelp (GetObjectRegistry ())) { csPrintf ("Usage: avatartest\n"); csPrintf ("Tests on animesh animation\n\n"); csPrintf ("Options for avatartest:\n"); csPrintf (" -model=<name>: set the starting model (frankie, krystal)\n"); csPrintf (" -no_physics: disable physical animations\n"); csCommandLineHelper::Help (GetObjectRegistry ()); return false; } if (!csInitializer::RequestPlugins (GetObjectRegistry (), CS_REQUEST_VFS, CS_REQUEST_OPENGL3D, CS_REQUEST_ENGINE, CS_REQUEST_FONTSERVER, CS_REQUEST_IMAGELOADER, CS_REQUEST_LEVELLOADER, CS_REQUEST_REPORTER, CS_REQUEST_REPORTERLISTENER, CS_REQUEST_PLUGIN ("crystalspace.mesh.animesh.controllers.lookat", iSkeletonLookAtManager2), CS_REQUEST_PLUGIN ("crystalspace.mesh.animesh.controllers.basic", iSkeletonBasicNodesManager2), CS_REQUEST_END)) return ReportError ("Failed to initialize plugins!"); csBaseEventHandler::Initialize (GetObjectRegistry ()); if (!RegisterQueue (GetObjectRegistry (), csevAllEvents (GetObjectRegistry ()))) return ReportError ("Failed to set up event handler!"); // Check if physics effects are enabled csRef<iCommandLineParser> clp = csQueryRegistry<iCommandLineParser> (GetObjectRegistry ()); physicsEnabled = !clp->GetBoolOption ("no_physics", false); if (physicsEnabled) { // Load the Bullet plugin csRef<iPluginManager> plugmgr = csQueryRegistry<iPluginManager> (GetObjectRegistry ()); dynamics = csLoadPlugin<iDynamics> (plugmgr, "crystalspace.dynamics.bullet"); if (!dynamics) { ReportWarning ("Can't load Bullet plugin, continuing with reduced functionalities"); physicsEnabled = false; } } // Read which model to display at first csString modelName = clp->GetOption ("model"); if (modelName != "krystal") avatarModel = MODEL_FRANKIE; else avatarModel = MODEL_KRYSTAL; return true; }
void SelfShadowDemo::LoadKrystal() { iSector* sector = engine->FindSector("Scene"); if (!sector) ReportError("Could not find default room!"); printf ("Loading Krystal...\n"); // Load animesh factory csLoadResult rc = loader->Load ("/lib/krystal/krystal.xml"); if (!rc.success) ReportError ("Can't load Krystal library file!"); csRef<iMeshFactoryWrapper> meshfact = engine->FindMeshFactory ("krystal"); if (!meshfact) ReportError ("Can't find Krystal's mesh factory!"); csRef<CS::Mesh::iAnimatedMeshFactory> animeshFactory = scfQueryInterface<CS::Mesh::iAnimatedMeshFactory> (meshfact->GetMeshObjectFactory ()); if (!animeshFactory) ReportError ("Can't find Krystal's animesh factory!"); // Create the animated mesh csRef<iMeshWrapper> avatarMesh = engine->CreateMeshWrapper (meshfact, "krystal", room, csVector3 (0.0f)); csRef<CS::Mesh::iAnimatedMesh> animesh = scfQueryInterface<CS::Mesh::iAnimatedMesh> (avatarMesh->GetMeshObject ()); avatarMesh->GetMovable()->SetSector(sector); avatarMesh->GetMovable()->UpdateMove(); // Load some fur rc = loader->Load ("/lib/hairtest/krystal_furmesh.xml"); if (!rc.success) ReportError ("Can't load krystal furmesh library!"); csRef<iMeshWrapper> krystalFurmeshObject = engine->FindMeshObject ("krystal_furmesh_object"); if (!krystalFurmeshObject) ReportError ("Can't find fur mesh object!"); krystalFurmeshObject->SetRenderPriority(engine->GetRenderPriority("alpha")); krystalFurmeshObject->GetMovable()->SetSector(sector); krystalFurmeshObject->GetMovable()->UpdateMove(); // Load the fur material rc = loader->Load ("/lib/hairtest/fur_material_krystal.xml"); if (!rc.success) ReportError ("Can't load Fur library file!"); // Find the fur mesh plugin csRef<CS::Mesh::iFurMeshType> furMeshType = csQueryRegistry<CS::Mesh::iFurMeshType> (GetObjectRegistry ()); if (!furMeshType) ReportError("Failed to locate CS::Mesh::iFurMeshType plugin!"); // Load the Marschner shader csRef<iMaterialWrapper> materialWrapper = engine->FindMaterial ("hair_trans"); if (!materialWrapper) ReportError ("Can't find marschner material!"); // Create the fur properties for the hairs csRef<CS::Mesh::iFurMeshMaterialProperties> hairMeshProperties = furMeshType->CreateHairMeshMarschnerProperties ("krystal_marschner"); hairMeshProperties->SetMaterial(materialWrapper->GetMaterial ()); // animesh->GetSubMesh (1)->SetMaterial (materialWrapper); csRef<CS::Animation::iFurAnimatedMeshControl> animationPhysicsControl = scfQueryInterface<CS::Animation::iFurAnimatedMeshControl> (furMeshType->CreateFurAnimatedMeshControl ("krystal_hairs_animation")); animationPhysicsControl->SetAnimatedMesh (animesh); csRef<iMeshObject> imo = krystalFurmeshObject->GetMeshObject(); // Get reference to the iFurMesh interface csRef<CS::Mesh::iFurMesh> furMesh = scfQueryInterface<CS::Mesh::iFurMesh> (imo); csRef<CS::Mesh::iFurMeshState> ifms = scfQueryInterface<CS::Mesh::iFurMeshState> (furMesh); animationPhysicsControl->SetDisplacement (ifms->GetDisplacement ()); furMesh->SetFurMeshProperties (hairMeshProperties); // Shader variables csRef<iShaderVarStringSet> svStrings = csQueryRegistryTagInterface<iShaderVarStringSet> ( object_reg, "crystalspace.shader.variablenameset"); if (!svStrings) ReportError ("No SV names string set!\n"); furMesh->SetAnimatedMesh (animesh); furMesh->SetMeshFactory (animeshFactory); furMesh->SetMeshFactorySubMesh (animesh->GetSubMesh (2)->GetFactorySubMesh ()); furMesh->GenerateGeometry (view, room); furMesh->SetAnimationControl (animationPhysicsControl); furMesh->StartAnimationControl (); furMesh->SetGuideLOD (0); furMesh->SetStrandLOD (1); furMesh->SetControlPointsLOD (0.0f); furMesh->ResetMesh (); }