How magotoolivesource/winwpi_framework works
Purpose and Deliverables
A native Windows 2D game framework built on WinAPI and GDI+, plus a Plants-vs.-Zombies-style sample game (“PVSZ”). The solution is FrameWork_2DAPI.sln; framework and game are separate Visual C++ projects: FrameWork_2DAPI/FrameWork_2DAPI.vcxproj and PVSZ/PVSZ.vcxproj.
Application Entry and Runtime Loop
Each executable is a WinAPI desktop application, with likely entry sources FrameWork_2DAPI/FrameWork_2DAPI.cpp and PVSZ/PVSZ.cpp. BaseGame owns the current scene, input, timer, GDI+ lifecycle, update, and rendering loop. Windows messages are translated into input state before per-frame simulation and draw.
• FrameWork_2DAPI/BaseGame.h
• FrameWork_2DAPI/BaseGame.cpp
• PVSZ/InGame_PVSZ.h
Entity-Component Scene Model
Scene owns GameObject instances; each object owns type-indexed component instances and always exposes a Transform. Scene lifecycle propagates Start, Update(dt), and Render(HDC) to objects, then components. This is the central boundary between game-specific composition and framework execution.
• FrameWork_2DAPI/Scene/Scene.h
• FrameWork_2DAPI/Core/GameObject.h
• FrameWork_2DAPI/Compoment/Component.h
Spatial, Rendering, and Asset Pipeline
Transform provides local/world position, rotation, scale, parent-child hierarchy, cached matrices, and depth. Renderable components draw through WinAPI device contexts using GDI+ images; camera and viewport transform/cull world content. ImageManager caches loaded Gdiplus::Image assets, sourced from each project’s Assets/Images.
• FrameWork_2DAPI/Compoment/Transform.h
• FrameWork_2DAPI/Compoment/ImageComponent.h
• FrameWork_2DAPI/Manager/ImageManager.h
• FrameWork_2DAPI/Compoment/Camera.h
Input, Time, Physics, and Debug Services
InputManager receives keyboard/mouse messages and exposes frame-readable state. TimerManager supplies delta and total time. Collider and rigidbody components are coordinated by collision/physics managers; debug-object facilities provide visual diagnostics. These are framework-wide services, largely singleton-style through SingletonT.
• FrameWork_2DAPI/Core/InputManager.h
• FrameWork_2DAPI/Core/TimerManager.h
• FrameWork_2DAPI/Manager/CollisionManager.h
• FrameWork_2DAPI/Manager/PhysicsManager.h
UI Boundary
UI is implemented as components sharing the same object/transform lifecycle. Buttons query input and execute callbacks; text, rich text, and input fields render via GDI+ and manage presentation/input state. Game UI composes these primitives for plant selection and top panels.
• FrameWork_2DAPI/UICompoment/Button.h
• FrameWork_2DAPI/UICompoment/RichTextAndInputFieldComponent.h
• PVSZ/UI_TopSelectPanelCom.h
PVSZ Gameplay Layer
PVSZ specializes the framework with a stage-driven game loop: Stage01 defines the level, StageWaveManager consumes wave data, and ZombieFactoryManager creates actors. Plants, zombies, peas, suns, movement, and actor state are components/actors orchestrated through game data and pooling. Object pooling separates frequent projectile/effect lifecycle from scene allocation.
• PVSZ/Stage01.h
• PVSZ/StageWaveManager.h
• PVSZ/ZombieFactoryManager.h
• PVSZ/ObjectPoolManager.h
• PVSZ/Actor_State_Com.h
External Platform Dependencies
Primary runtime dependencies are Windows/WinAPI (HDC, window messages, resources) and GDI+ (Gdiplus::Image, matrices, fonts, drawing). No networked services or external backend are indicated. Asset delivery is filesystem-based under framework and PVSZ asset directories.
• FrameWork_2DAPI/framework.h
• FrameWork_2DAPI/FrameWork_2DAPI.rc
• PVSZ/PVSZ.rc
Main entry points: InGame_PVSZ.h PVSZ game scene · BaseGame.cpp BaseGame runtime loop · Camera.h Camera & image rendering · GameObject.h GameObject
Components 19
2D Framework
Reusable WinAPI and GDI+ runtime.
- Framework executable
FrameWork_2DAPI/FrameWork_2DAPI.cpp - BaseGame runtime loop · Owns scene, frame update, rendering, and GDI+ lifecycle.
FrameWork_2DAPI/BaseGame.cpp - Scene · Propagates Start, Update, and Render to game objects.
FrameWork_2DAPI/Scene/Scene.h - GameObject · Owns components and always exposes a Transform.
FrameWork_2DAPI/Core/GameObject.h - Component model
FrameWork_2DAPI/Compoment/Component.h - Transform · Provides hierarchy, cached transforms, and depth.
FrameWork_2DAPI/Compoment/Transform.h - Camera & image rendering · Transforms, culls, and draws world content to HDC.
FrameWork_2DAPI/Compoment/Camera.h - ImageManager · Caches GDI+ image assets.
FrameWork_2DAPI/Manager/ImageManager.h - Input, time & physics · Converts messages to input and coordinates timing and collision/physics.
FrameWork_2DAPI/Core/InputManager.h - UI components · Buttons, rich text, and fields share object lifecycle.
FrameWork_2DAPI/UICompoment/Button.h
PVSZ Game
Plants-vs.-Zombies-style game layer.
- PVSZ executable
PVSZ/PVSZ.cpp - PVSZ game scene · Specializes the framework runtime for gameplay.
PVSZ/InGame_PVSZ.h - Stage01 & waves · Defines the level and consumes wave data.
PVSZ/Stage01.h - ZombieFactoryManager · Creates zombie actors for stage waves.
PVSZ/ZombieFactoryManager.h - Actor state · Coordinates plants, zombies, projectiles, suns, and movement.
PVSZ/Actor_State_Com.h - ObjectPoolManager · Reuses frequent projectile and effect objects.
PVSZ/ObjectPoolManager.h - Top selection UI · Composes plant selection and top-panel presentation.
PVSZ/UI_TopSelectPanelCom.h
Other components
- Windows / WinAPI · Desktop window, messages, device contexts, and resources.
FrameWork_2DAPI/framework.h - GDI+ · Images, matrices, fonts, and drawing.
Connections 21
- Framework executable → BaseGame runtime loop: starts
- PVSZ executable → PVSZ game scene: starts
- PVSZ game scene → BaseGame runtime loop: uses runtime
- Windows / WinAPI → BaseGame runtime loop: messages and HDC
- BaseGame runtime loop → Scene: owns current scene
- BaseGame runtime loop → Input, time & physics: updates services
- Scene → GameObject: owns entities
- GameObject → Component model: owns typed components
- GameObject → Transform: includes
- Component model → Camera & image rendering: implements rendering
- Transform → Camera & image rendering: world transforms
- Camera & image rendering → ImageManager: loads cached images
- Camera & image rendering → GDI+: draws through
- UI components → Input, time & physics: reads input
- PVSZ game scene → Stage01 & waves: runs level
- Stage01 & waves → ZombieFactoryManager: spawns waves
- ZombieFactoryManager → Actor state: creates actors
- Actor state → ObjectPoolManager: reuses transient objects
- PVSZ game scene → Top selection UI: composes UI
- Top selection UI → UI components: uses primitives
- PVSZ game scene → Scene: composes objects