- Added documentation for Overte authentication implementation in `docs/OVERTE_AUTH.md`. - Introduced new GLB files for cube and sphere primitives in `examples/primitives/`. - Created a JSON file `examples/test_entities.json` containing sample entities for testing. - Added a build and test script `scripts/build_and_test.sh` for streamlined building and verification of the project. - Implemented a CI test runner script `scripts/ci-test.sh` to automate testing processes. - Created a script `scripts/run_with_auth.sh` to facilitate running the Starworld client with Overte authentication.
7.1 KiB
Code Cleanup Summary
✅ Completed Cleanup (All changes successfully compiled)
1. Standardized Anonymous Namespaces ✅
Before: Inconsistent mix of static functions and anonymous namespaces
After: All internal implementation details use anonymous namespaces
StardustBridge.cpp
- ✅ Converted
static candidateSocketPaths()→ anonymous namespace - ✅ Removed
StardustBridge::defaultSocketPath()(was public static, only used internally) - ✅ Updated header comment to reflect socket auto-discovery
- ✅ Alphabetized includes, grouped by category (STL, system headers)
NLPacketCodec.cpp
- ✅ Converted 5
static constexprbit masks → anonymous namespace constants - ✅ Converted 4 static helper functions → anonymous namespace:
readFileToString()parseEnumValues()parsePacketTypeCount()ensureVersionTable()
DomainDiscovery.cpp
- ✅ Kept existing anonymous namespace for
httpGet()andwrite_cb - ✅ Converted 2 static JSON helpers → anonymous namespace:
findAllStrings()findAllInts()
2. Cleaned Up Includes ✅
Before: Headers duplicated in .cpp files, unsorted includes
After: Alphabetized includes, removed redundancies, grouped by type
StardustBridge.cpp
// Before: 19 unsorted includes
#include <chrono>
#include <sys/socket.h>
#include <vector>
// ... mixed order
// After: Grouped and alphabetized
#include <algorithm>
#include <chrono>
// ... STL headers alphabetically
#include <dlfcn.h>
#include <fcntl.h>
// ... system headers alphabetically
DomainDiscovery.cpp
// Before: Mixed includes with comments
#include <iostream>
#include <string> // Already in header (std::string)
#include <vector> // Already in header
// Minimal libcurl-based GET
#include <curl/curl.h>
// After: Clean, alphabetized, no redundant std::string/vector
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <optional>
#include <sstream>
#include <curl/curl.h>
#include <arpa/inet.h>
// ... system headers alphabetically
ModelCache.cpp
// Before: Includes with inline comments
#include <iostream>
#include <thread>
#include <cstring>
// For HTTP downloads - using libcurl (cross-platform)
#include <curl/curl.h>
// For hashing URLs to filenames
#include <openssl/sha.h>
// After: Clean and alphabetized
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <thread>
#include <curl/curl.h>
#include <openssl/sha.h>
3. Removed Public API Bloat ✅
StardustBridge.hpp
Removed: static std::string defaultSocketPath()
- Was a public static method but only used internally in
connect() - Implementation now private in anonymous namespace within .cpp
- Cleaner public API surface
Before (StardustBridge.hpp):
public:
bool connect(const std::string& socketPath = {});
// ... other methods
static std::string defaultSocketPath(); // ❌ Exposed unnecessarily
After (StardustBridge.hpp):
public:
bool connect(const std::string& socketPath = {});
// ... other methods
// defaultSocketPath removed - internal detail only
4. Improved Code Organization ✅
All files now follow consistent pattern:
#include "Header.hpp"
// STL includes (alphabetically)
#include <algorithm>
#include <string>
#include <vector>
// System includes (alphabetically)
#include <curl/curl.h>
#include <sys/socket.h>
namespace {
// Internal constants
constexpr uint32_t MASK = 0x80000000;
// Internal helper functions
void helperFunction() { ... }
} // anonymous namespace
// Public API implementations
void PublicClass::publicMethod() { ... }
Impact Summary
Code Metrics
- Lines removed: ~35 (redundant includes, removed public method)
- Public API surface: Reduced by 1 method (defaultSocketPath)
- Consistency: 100% of internal helpers now use anonymous namespaces
- Build time: No change (same compilation units)
- Binary size: No change (same code, different organization)
Benefits
✅ Clarity: Clear separation of public API vs internal implementation
✅ Consistency: All internal helpers use same pattern (anonymous namespace)
✅ Maintainability: Alphabetized includes easier to scan
✅ Encapsulation: Reduced public API surface
✅ Modern C++: Following best practices (anonymous namespace > static)
Files Modified
- ✅
src/StardustBridge.cpp- Anonymous namespace, alphabetized includes - ✅
src/StardustBridge.hpp- Removed defaultSocketPath() - ✅
src/NLPacketCodec.cpp- Anonymous namespace for all helpers - ✅
src/DomainDiscovery.cpp- Anonymous namespace, cleaned includes - ✅
src/ModelCache.cpp- Alphabetized includes
Verified
✅ Build successful: starworld (305KB), starworld-tests (106KB)
✅ No behavior changes - pure refactoring
✅ No new warnings or errors
What We Did NOT Change (Intentionally Kept)
✅ Good Patterns Already Present
- Anonymous namespaces in ModelCache.cpp: Already well-organized ✅
- Anonymous namespace in OverteClient.cpp: Already well-organized ✅
- Static class SceneSync: Appropriate use of static methods ✅
- Header guards using
#pragma once: Modern and clean ✅ - Smart pointers and std::optional: Modern C++ patterns ✅
📝 Functions Kept Public (For Good Reasons)
parseDomainsFromJson()in DomainDiscovery.hpp: Marked "for tests"- Decision: Keep public for future test usage
- Alternative considered: Move to anonymous namespace
- Rationale: Exported for testability
🎯 Design Decisions Validated
- Constants in .cpp files (not headers) ✅ Correct - reduces recompilation
- Forward declarations where appropriate ✅ Reduces include dependencies
- Separate .hpp/.cpp files ✅ Clean interface/implementation separation
Next Steps (Future Work)
Optional Further Cleanup
- ⏭️ Add unit tests that use
parseDomainsFromJson()(currently unused) - ⏭️ Consider forward declarations to reduce header includes
- ⏭️ Document remaining design patterns (e.g., SceneSync static class)
Feature Development (Resume)
Now that codebase is cleaned up, ready to continue:
- ATP protocol support
- Parse all entity types from EntityTypes.h
- Entity property updates
- Entity deletion handling
- Testing with real/local Overte server
Lessons Learned
✅ C++ Best Practices Applied
- Anonymous namespaces >
static: Better for translation unit scope - Minimize public API: Only expose what's truly needed
- Organize includes: Alphabetically, grouped by type
- Remove redundancy: Don't re-include what's in headers
- Consistency: Apply patterns uniformly across codebase
🎯 Trade-offs Made
- Verbosity: Anonymous namespace adds 2 lines per file
- Benefit: Clarity outweighs brevity
- Include sorting: Takes time to reorganize
- Benefit: Easier to spot duplicates and missing includes
- Public API reduction: Removed potentially "useful" utility
- Benefit: Users can't depend on internal implementation details