void Main(PlatformAPI *api) { // Application settings Application app; app.api = api; SetApplicationTitle(api, "CPU Rasterizer"); // Mouse setup app.mouse_exclusive = true; app.mouse_sensitivity = 0.8f * 0.0022f; // Sensitivity * source engine scale // Setup player properties app.player_yaw = 0.0f; app.player_pitch = 0.0f; app.player_flags = 0; // Setup camera app.camera.pos = float3(0.0f, 0.0f, -8.0f); app.camera.fov = Tau * 0.25f; // Setup scene CreateTestScene(app.scene); // Set events SetKeyboardEvent(api, &app, OnKeyboardEvent); SetMouseEvent(api, &app, OnMouseEvent); SetMouseCaptureMode(api, MouseCaptureModeExclusive); // Create software renderer app.renderer = CreateSoftwareRenderer(api, 1280, 720, false); // Load default font. app.font = CreateFontFromFile("C:\\Windows\\Fonts\\calibrib.ttf", 18.0f); // Initialize the rasterizer data { app.frame_info = NULL; // Default framebuffer app.framebuffer.width = 1280; app.framebuffer.height = 720; U32 size = GetRequiredMemoryAmount(app.framebuffer, true, true); Initialize(app.framebuffer, malloc(size), true, true); // Threads CreateRasterizerThreads(app); } // Frame update loop U64 frame_start_time = GetTime(api); app.frame_delta = 0.0001f; while (Update(api)) { // Apply player rotation to camera. app.camera.axis[0] = float3(1.0f, 0.0f, 0.0f); app.camera.axis[1] = float3(0.0f, 1.0f, 0.0f); app.camera.axis[2] = float3(0.0f, 0.0f, 1.0f); Rotate(app.camera.axis[0], float3(1.0f, 0.0f, 0.0f), app.player_pitch); Rotate(app.camera.axis[1], float3(1.0f, 0.0f, 0.0f), app.player_pitch); Rotate(app.camera.axis[2], float3(1.0f, 0.0f, 0.0f), app.player_pitch); Rotate(app.camera.axis[0], float3(0.0f, 1.0f, 0.0f), app.player_yaw); Rotate(app.camera.axis[1], float3(0.0f, 1.0f, 0.0f), app.player_yaw); Rotate(app.camera.axis[2], float3(0.0f, 1.0f, 0.0f), app.player_yaw); // Apply player movement to camera float3 player_velocity = 0.0f; if (app.player_flags & PlayerFlagMoveForward) player_velocity += app.camera.axis[2]; if (app.player_flags & PlayerFlagMoveBackward) player_velocity -= app.camera.axis[2]; if (app.player_flags & PlayerFlagMoveRight) player_velocity -= app.camera.axis[0]; if (app.player_flags & PlayerFlagMoveLeft) player_velocity += app.camera.axis[0]; if (Dot(player_velocity, player_velocity) != 0.0f) Normalize(player_velocity); player_velocity *= 5.0f * app.frame_delta; app.camera.pos += player_velocity; // Render the frame LockBufferInfo frame_info; LockBuffer(app.renderer, frame_info); RenderFrame(app, frame_info); PrintDebugStats(app, frame_info); UnlockBuffer(app.renderer); // Calculate frame delta time U64 time = GetTime(api); U64 delta = time - frame_start_time; frame_start_time = time; app.frame_delta = float(delta) / float(U64(1) << U64(32)); } }
ShutDownType Master::Run(int argc, char **argv) { new Config; std::vector<const char*> files; files.push_back("server.properties"), files.push_back("misc.properties"), files.push_back("character.properties"); std::string path = "./config"; if(argc >= 2) path = argv[1]; Config::Instance().Init(path, files); new Log(m_service); Log::Instance().Init(Config::Instance().GetParam<std::string>(LOGS_PATH_STRING, LOGS_PATH_DEFAULT).c_str(), Config::Instance().GetParam<uint8>(LOGS_LEVEL_STRING, LOGS_LEVEL_DEFAULT)); SetApplicationTitle("Desperion GameServer v%u.%u.%u", GAME_VERSION_MAJOR, GAME_VERSION_MINOR, GAME_VERSION_REVISION); Log::Instance().OutColor(TBLUE, ",------, ,-----. ,-----, ,------. ,-----. ,------. ,------. ,------, ,, ,,"); Log::Instance().OutColor(TBLUE, "| ,--, ` | .---' | ,--` | ,--, | | .---' | ,--, | `--||--' | ,--, | ||\\ ||"); Log::Instance().OutColor(TBLUE, "| | | | | |--. | `--, | | | | | |--. | | | | || | | | | || \\ ||"); Log::Instance().OutColor(TBLUE, "| | | | | |--' `---, | | `--` | | |--' | `--` , || | | | | || \\ ||"); Log::Instance().OutColor(TBLUE, "| '--' , | '---, ,---| | | ,----` | '---, | ,-\\ \\ .--||--, | '--' | || \\||"); Log::Instance().OutColor(TBLUE, "`------` `-----' `-----` `-` `-----' `-` '--' `------` `------` `` `'\n"); Log::Instance().OutColor(TWHITE, "Dofus v%u.%u.%u.%u.%u.%u, protocol %u/%u", DOFUS_VERSION_MAJOR, DOFUS_VERSION_MINOR, DOFUS_VERSION_RELEASE, DOFUS_VERSION_REVISION, DOFUS_VERSION_PATCH, DOFUS_VERSION_BUILD_TYPE, PROTOCOL_BUILD, PROTOCOL_REQUIRED_BUILD); Log::Instance().OutColor(TWHITE, "GameServer v%u.%u.%u", GAME_VERSION_MAJOR, GAME_VERSION_MINOR, GAME_VERSION_REVISION); Log::Instance().OutColor(TWHITE, "Shared v%u.%u.%u\n\n", SHARED_VERSION_MAJOR, SHARED_VERSION_MINOR, SHARED_VERSION_REVISION); if(!StartUpDatabase()) return SHUTDOWN_NORMAL; /*ResultPtr QR = sDatabase->Query("SELECT id, effects FROM d2o_item_set;"); barGoLink go(QR->GetRowCount()); while(QR->NextRow()) { Field* fields = QR->Fetch(); std::vector<std::string> table; std::ostringstream effects; Desperion::FastSplitString<':'>(table, std::string(fields[1].GetString())); effects<<table.size(); for(size_t a = 0; a < table.size(); ++a) { effects<<":"; std::vector<std::string> table2; Desperion::FastSplitString<';'>(table2, table[a]); effects<<table2.size(); for(size_t b = 0; b < table2.size(); ++b) { effects<<";"; std::vector<int> table3; Desperion::FastSplit<','>(table3, table2[b], Desperion::SplitInt); effects<<3<<","<<OBJECT_EFFECT_INTEGER<<","<<table3[2]<<","<<table3[6]; } } sDatabase->Execute("UPDATE d2o_item_set SET effects='%s' WHERE id=%u;", effects.str().c_str(), fields[0].GetInt32()); go.step(); } return SHUTDOWN_NORMAL;*/ new World; World::Instance().Init(); SocketListener<Session> sListener(ThreadPool::Instance().GetService(), Config::Instance().GetParam(LOCAL_SERVER_PORT_STRING, LOCAL_SERVER_PORT_DEFAULT)); Log::Instance().OutNotice("Network", "Listening for Dofus clients on port %u", Config::Instance().GetParam(LOCAL_SERVER_PORT_STRING, LOCAL_SERVER_PORT_DEFAULT)); new GameClient(ThreadPool::Instance().GetService()); GameClient::Instance().Launch(); std::cout<<std::endl; Log::Instance().OutString("Uptime: %ums", GetUpTime()); Log::Instance().OutColor(TBLUE, "Type Ctrl+C to safely shutdown the server.\n"); HookSignals(); HookSignals(); while(m_shutdown == SHUTDOWN_NOT_REQUESTED) { m_service.reset(); ThreadPool::Instance().SpawnWorkerThreads(); m_service.run(); ThreadPool::Instance().ClearWorkerThreads(); } UnHookSignals(); return m_shutdown; }