Add auto-connect for local development and refactor main.cpp#260
Add auto-connect for local development and refactor main.cpp#260
Conversation
Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
|
@copilot That main file looks pretty gnarly, what sort of improvements can be made. You don't have to be super surgical as this file doesn't follow best practices very well |
Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
Refactored the 264-line main() function into a clean ClientApp class with proper separation of concerns. Main improvements:
The refactoring maintains all existing functionality while making the code significantly more maintainable. See commit bdc7407. |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the client's main entry point by extracting initialization and lifecycle logic from main.cpp into a new ClientApp class, improving code organization and maintainability. It also adds auto-connect functionality for local development.
- Extracted ~220 lines of initialization code into a dedicated
ClientAppclass with proper encapsulation - Added auto-connect feature to streamline local development workflow
- Converted helper functions to anonymous namespace for better encapsulation
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| client/main.cpp | Simplified to create and run ClientApp instance |
| client/client-app.hpp | Defines ClientApp class with initialization methods and member variables |
| client/client-app.cpp | Implements ClientApp with refactored initialization logic and auto-connect feature |
| client/CMakeLists.txt | Adds client-app.cpp to build configuration |
| README.md | Documents auto-connect configuration for local development |
…ating CMake requirements, and refining keyboard input handling
Update CI configuration to use Ubuntu 22.04 for consistency across environments Add arch to upload-artifact name
Manual login on every startup is cumbersome for local development. Added optional auto-connect to localhost with pre-configured username. Additionally, refactored the monolithic main.cpp file into a well-structured ClientApp class for better maintainability.
Changes
client/main.cpp
client/client-app.hpp & client/client-app.cpp (NEW)
InitializeLogger()- Logger setupInitializeWindow()- OpenGL window creationInitializeGame()- Game system initializationInitializeGUI()- GUI system and windowsRegisterConsoleCommands()- Console command registrationSetupAutoConnect()- Auto-connect logicRegisterGUIWindows()- GUI window registrationRun()- Main game loopclient/CMakeLists.txt
README.md
Auto-Connect Configuration
Auto-connect follows same pattern as existing GUI and console connection methods:
RegisterConnectFunc→RegisterMessageHandler→Connect. Registers handlers beforeConnect()to avoid race condition with AUTHENTICATED message.Refactoring Benefits
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.