summary refs log tree commit diff stats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/Main.cpp225
-rw-r--r--Source/Main.h3
-rw-r--r--Source/Memory.h2
-rw-r--r--Source/Randomizer.cpp50
-rw-r--r--Source/Randomizer.h2
-rw-r--r--Source/Source.vcxproj3
-rw-r--r--Source/Source.vcxproj.filters3
7 files changed, 128 insertions, 160 deletions
diff --git a/Source/Main.cpp b/Source/Main.cpp index 4748b73..5c7cefa 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp
@@ -2,177 +2,162 @@
2// 2//
3 3
4#include "stdafx.h" 4#include "stdafx.h"
5#include "Main.h" 5#include "resource.h"
6#include "tchar.h"
7#include "Randomizer.h"
8#include <Richedit.h>
9#include <iostream>
10#include <ctime>
11#include <string>
6 12
7#define MAX_LOADSTRING 100 13#define MAX_LOADSTRING 100
14#define IDC_RANDOMIZE 0x464
8 15
9// Global Variables: 16HINSTANCE hInst;
10HINSTANCE hInst; // current instance 17WCHAR szWindowClass[MAX_LOADSTRING];
11WCHAR szTitle[MAX_LOADSTRING]; // The title bar text 18HWND hwndSeed;
12WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name 19std::shared_ptr<Randomizer> randomizer;
13 20
14// Forward declarations of functions included in this code module: 21// Forward declares
15ATOM MyRegisterClass(HINSTANCE hInstance); 22ATOM MyRegisterClass(HINSTANCE hInstance);
16BOOL InitInstance(HINSTANCE, int); 23BOOL InitInstance(HINSTANCE, int);
17LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 24LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
18INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); 25INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
19 26
20int APIENTRY wWinMain(_In_ HINSTANCE hInstance, 27int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
21 _In_opt_ HINSTANCE hPrevInstance,
22 _In_ LPWSTR lpCmdLine,
23 _In_ int nCmdShow)
24{ 28{
25 UNREFERENCED_PARAMETER(hPrevInstance); 29 LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING);
26 UNREFERENCED_PARAMETER(lpCmdLine);
27
28 // TODO: Place code here.
29
30 // Initialize global strings
31 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
32 LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING);
33 MyRegisterClass(hInstance); 30 MyRegisterClass(hInstance);
34 31 if (!InitInstance(hInstance, nCmdShow)) {
35 // Perform application initialization:
36 if (!InitInstance (hInstance, nCmdShow))
37 {
38 return FALSE; 32 return FALSE;
39 } 33 }
40 34 randomizer = std::make_shared<Randomizer>();
41 HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SOURCE)); 35 if (randomizer == nullptr) {
36 return FALSE;
37 }
42 38
43 MSG msg; 39 MSG msg;
44 40 while (!GetMessage(&msg, nullptr, 0, 0) == 0)
45 // Main message loop:
46 while (GetMessage(&msg, nullptr, 0, 0))
47 { 41 {
48 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 42 TranslateMessage(&msg);
49 { 43 DispatchMessage(&msg);
50 TranslateMessage(&msg);
51 DispatchMessage(&msg);
52 }
53 } 44 }
54 45
55 return (int) msg.wParam; 46 return (int) msg.wParam;
56} 47}
57 48
58
59
60//
61// FUNCTION: MyRegisterClass()
62//
63// PURPOSE: Registers the window class.
64//
65ATOM MyRegisterClass(HINSTANCE hInstance) 49ATOM MyRegisterClass(HINSTANCE hInstance)
66{ 50{
67 WNDCLASSEXW wcex; 51 WNDCLASSEXW wcex = {
68 52 sizeof(WNDCLASSEX),
69 wcex.cbSize = sizeof(WNDCLASSEX); 53 CS_HREDRAW | CS_VREDRAW,
70 54 WndProc,
71 wcex.style = CS_HREDRAW | CS_VREDRAW; 55 0,
72 wcex.lpfnWndProc = WndProc; 56 0,
73 wcex.cbClsExtra = 0; 57 hInstance,
74 wcex.cbWndExtra = 0; 58 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SOURCE)),
75 wcex.hInstance = hInstance; 59 LoadCursor(nullptr, IDC_ARROW),
76 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SOURCE)); 60 (HBRUSH)(COLOR_WINDOW+1),
77 wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); 61 MAKEINTRESOURCEW(IDC_SOURCE),
78 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 62 szWindowClass,
79 wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_SOURCE); 63 LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)),
80 wcex.lpszClassName = szWindowClass; 64 };
81 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
82 65
83 return RegisterClassExW(&wcex); 66 return RegisterClassExW(&wcex);
84} 67}
85 68
86//
87// FUNCTION: InitInstance(HINSTANCE, int)
88//
89// PURPOSE: Saves instance handle and creates main window
90//
91// COMMENTS:
92//
93// In this function, we save the instance handle in a global variable and
94// create and display the main program window.
95//
96BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 69BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
97{ 70{
98 hInst = hInstance; // Store instance handle in our global variable 71 hInst = hInstance; // Store instance handle in our global variable
99 72
100 HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 73 WCHAR szTitle[MAX_LOADSTRING];
74 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
75 HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
101 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); 76 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
102 77
103 if (!hWnd) 78 if (!hWnd)
104 { 79 {
105 return FALSE; 80 return FALSE;
106 } 81 }
107 82
108 ShowWindow(hWnd, nCmdShow); 83 LoadLibrary(L"Msftedit.dll");
109 UpdateWindow(hWnd); 84 HWND label = CreateWindow(L"BUTTON", L"Enter a seed:",
110 85 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
111 return TRUE; 86 10, 10, 100, 26, hWnd, NULL, hInst, NULL);
87
88 hwndSeed = CreateWindowEx(0, MSFTEDIT_CLASS, L"",
89 ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP,
90 120, 10, 50, 26, hWnd, NULL, hInst, NULL);
91
92 HWND hwndRandomize = CreateWindow(L"BUTTON", L"Randomize",
93 WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
94 180, 10, 100, 26, hWnd, (HMENU)IDC_RANDOMIZE, hInst, NULL);
95
96 HDC hdc = GetDC(hWnd);
97 RECT rect;
98 GetClientRect(hWnd, &rect);
99 LPCWSTR text = L"this Window cannot be used";
100 DrawText(hdc, text, static_cast<int>(wcslen(text)), &rect, DT_CENTER | DT_VCENTER);
101 ReleaseDC(hWnd, hdc);
102
103 ShowWindow(hWnd, nCmdShow);
104 UpdateWindow(hWnd);
105 return TRUE;
112} 106}
113 107
114//
115// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
116//
117// PURPOSE: Processes messages for the main window.
118//
119// WM_COMMAND - process the application menu
120// WM_PAINT - Paint the main window
121// WM_DESTROY - post a quit message and return
122//
123//
124LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 108LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
125{ 109{
126 switch (message) 110 if (WM_COMMAND == WM_DESTROY) {
127 { 111 PostQuitMessage(0);
128 case WM_COMMAND: 112 } else {
129 { 113 int wmId = LOWORD(wParam);
130 int wmId = LOWORD(wParam); 114 // Parse the menu selections:
131 // Parse the menu selections: 115 switch (wmId)
132 switch (wmId)
133 {
134 case IDM_ABOUT:
135 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
136 break;
137 case IDM_EXIT:
138 DestroyWindow(hWnd);
139 break;
140 default:
141 return DefWindowProc(hWnd, message, wParam, lParam);
142 }
143 }
144 break;
145 case WM_PAINT:
146 { 116 {
147 PAINTSTRUCT ps; 117 case IDM_ABOUT:
148 HDC hdc = BeginPaint(hWnd, &ps); 118 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
149 // TODO: Add any drawing code that uses hdc here... 119 break;
150 EndPaint(hWnd, &ps); 120 case IDC_RANDOMIZE:
121 {
122 std::wstring text(100, '\0');
123 GetWindowText(hwndSeed, &text[0], 100);
124 int seed = 0;
125 if (wcslen(text.c_str()) == 0) {
126 srand(static_cast<unsigned int>(time(nullptr))); // Seed from the time in milliseconds
127 rand();
128 seed = rand() % 100000;
129 std::wstring seedString = std::to_wstring(seed);
130 SetWindowText(hwndSeed, seedString.c_str());
131 } else {
132 seed = _wtoi(text.c_str());
133 }
134 randomizer->Randomize(seed);
135
136 break;
137 }
138 case IDM_EXIT:
139 DestroyWindow(hWnd);
140 break;
141 default:
142 return DefWindowProc(hWnd, message, wParam, lParam);
151 } 143 }
152 break; 144 }
153 case WM_DESTROY: 145 return DefWindowProc(hWnd, message, wParam, lParam);
154 PostQuitMessage(0);
155 break;
156 default:
157 return DefWindowProc(hWnd, message, wParam, lParam);
158 }
159 return 0;
160} 146}
161 147
162// Message handler for about box.
163INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 148INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
164{ 149{
165 UNREFERENCED_PARAMETER(lParam); 150 UNREFERENCED_PARAMETER(lParam);
166 switch (message) 151 switch (message)
167 { 152 {
168 case WM_INITDIALOG: 153 case WM_INITDIALOG:
169 return (INT_PTR)TRUE; 154 return TRUE;
170 155
171 case WM_COMMAND: 156 case WM_COMMAND:
172 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 157 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
173 { 158 {
174 EndDialog(hDlg, LOWORD(wParam)); 159 EndDialog(hDlg, LOWORD(wParam));
175 return (INT_PTR)TRUE; 160 return TRUE;
176 } 161 }
177 break; 162 break;
178 } 163 }
diff --git a/Source/Main.h b/Source/Main.h deleted file mode 100644 index d00d47e..0000000 --- a/Source/Main.h +++ /dev/null
@@ -1,3 +0,0 @@
1#pragma once
2
3#include "resource.h"
diff --git a/Source/Memory.h b/Source/Memory.h index 8e8bbc3..53fa1e0 100644 --- a/Source/Memory.h +++ b/Source/Memory.h
@@ -39,7 +39,7 @@ public:
39 } 39 }
40 ThrowError(); 40 ThrowError();
41 } 41 }
42 42
43private: 43private:
44 void ThrowError(); 44 void ThrowError();
45 45
diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 75b3cf7..b8462e5 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp
@@ -6,7 +6,6 @@
6 This seems to cause crashes when pivots appear elsewhere in the world. 6 This seems to cause crashes when pivots appear elsewhere in the world.
7 * Some panels are impossible casually: (idc, I think) 7 * Some panels are impossible casually: (idc, I think)
8 ** Town Stars, Invisible dots 8 ** Town Stars, Invisible dots
9 * Shadows burn marks are not appearing
10 * Something is wrong with jungle re: softlocks 9 * Something is wrong with jungle re: softlocks
11 * FEATURES: 10 * FEATURES:
12 * SWAP_TARGETS should still require the full panel sequence (and have ways to prevent softlocks?) 11 * SWAP_TARGETS should still require the full panel sequence (and have ways to prevent softlocks?)
@@ -37,34 +36,23 @@ size_t find(const std::vector<T> &data, T search, size_t startIndex = 0) {
37 exit(-1); 36 exit(-1);
38} 37}
39 38
40int main(int argc, char** argv) 39void Randomizer::Randomize(int seed)
41{ 40{
42 Randomizer randomizer = Randomizer();
43
44 if (argc == 2) {
45 srand(atoi(argv[1])); // Seed from the command line
46 } else {
47 srand(static_cast<unsigned int>(time(nullptr)));
48 int seed = rand() % (1 << 16); // Seed from the time in milliseconds
49 std::cout << "Selected seed: " << seed << std::endl;
50 srand(seed);
51 }
52
53 // Content swaps -- must happen before squarePanels 41 // Content swaps -- must happen before squarePanels
54 randomizer.Randomize(tallUpDownPanels, SWAP_LINES | SWAP_STYLE); 42 Randomize(tallUpDownPanels, SWAP_LINES | SWAP_STYLE);
55 randomizer.Randomize(upDownPanels, SWAP_LINES | SWAP_STYLE); 43 Randomize(upDownPanels, SWAP_LINES | SWAP_STYLE);
56 randomizer.Randomize(leftForwardRightPanels, SWAP_LINES); 44 Randomize(leftForwardRightPanels, SWAP_LINES);
57 45
58 randomizer.Randomize(squarePanels, SWAP_LINES | SWAP_STYLE); 46 Randomize(squarePanels, SWAP_LINES | SWAP_STYLE);
59 47
60 // Frame swaps -- must happen after squarePanels 48 // Frame swaps -- must happen after squarePanels
61 randomizer.Randomize(burnablePanels, SWAP_LINES | SWAP_STYLE); 49 Randomize(burnablePanels, SWAP_LINES | SWAP_STYLE);
62 50
63 // Target swaps, can happen whenever 51 // Target swaps, can happen whenever
64 randomizer.Randomize(lasers, SWAP_TARGETS); 52 Randomize(lasers, SWAP_TARGETS);
65 // Read the target of keep front laser, and write it to keep back laser. 53 // Read the target of keep front laser, and write it to keep back laser.
66 std::vector<int> keepFrontLaserTarget = randomizer.ReadPanelData<int>(0x0360E, TARGET, 1); 54 std::vector<int> keepFrontLaserTarget = ReadPanelData<int>(0x0360E, TARGET, 1);
67 randomizer.WritePanelData<int>(0x03317, TARGET, keepFrontLaserTarget); 55 WritePanelData<int>(0x03317, TARGET, keepFrontLaserTarget);
68 56
69 std::vector<int> randomOrder; 57 std::vector<int> randomOrder;
70 58
@@ -77,7 +65,7 @@ int main(int argc, char** argv)
77 // Randomize Pitches 1-6 onto themselves 65 // Randomize Pitches 1-6 onto themselves
78 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 7, 13); 66 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 7, 13);
79 randomizer.ReassignTargets(junglePanels, randomOrder); 67 randomizer.ReassignTargets(junglePanels, randomOrder);
80 */ 68 */
81 69
82 /* Bunker */ 70 /* Bunker */
83 randomOrder = std::vector(bunkerPanels.size(), 0); 71 randomOrder = std::vector(bunkerPanels.size(), 0);
@@ -85,23 +73,23 @@ int main(int argc, char** argv)
85 // Randomize Tutorial 2-Advanced Tutorial 4 + Glass 1 73 // Randomize Tutorial 2-Advanced Tutorial 4 + Glass 1
86 // Tutorial 1 cannot be randomized, since no other panel can start on 74 // Tutorial 1 cannot be randomized, since no other panel can start on
87 // Glass 1 will become door + glass 1, due to the targetting system 75 // Glass 1 will become door + glass 1, due to the targetting system
88 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 1, 10); 76 RandomizeRange(randomOrder, SWAP_NONE, 1, 10);
89 // Randomize Glass 1-3 into everything after the door 77 // Randomize Glass 1-3 into everything after the door
90 const size_t glassDoorIndex = find(randomOrder, 9) + 1; 78 const size_t glassDoorIndex = find(randomOrder, 9) + 1;
91 randomizer.RandomizeRange(randomOrder, SWAP_NONE, glassDoorIndex, 12); 79 RandomizeRange(randomOrder, SWAP_NONE, glassDoorIndex, 12);
92 randomizer.ReassignTargets(bunkerPanels, randomOrder); 80 ReassignTargets(bunkerPanels, randomOrder);
93 81
94 /* Shadows */ 82 /* Shadows */
95 randomOrder = std::vector(shadowsPanels.size(), 0); 83 randomOrder = std::vector(shadowsPanels.size(), 0);
96 std::iota(randomOrder.begin(), randomOrder.end(), 0); 84 std::iota(randomOrder.begin(), randomOrder.end(), 0);
97 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 0, 8); // Tutorial 85 RandomizeRange(randomOrder, SWAP_NONE, 0, 8); // Tutorial
98 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid 86 RandomizeRange(randomOrder, SWAP_NONE, 8, 16); // Avoid
99 randomizer.RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow 87 RandomizeRange(randomOrder, SWAP_NONE, 16, 21); // Follow
100 randomizer.ReassignTargets(shadowsPanels, randomOrder); 88 ReassignTargets(shadowsPanels, randomOrder);
101 // Turn off original starting panel 89 // Turn off original starting panel
102 randomizer.WritePanelData<float>(shadowsPanels[0], POWER, {0.0f, 0.0f}); 90 WritePanelData<float>(shadowsPanels[0], POWER, {0.0f, 0.0f});
103 // Turn on new starting panel 91 // Turn on new starting panel
104 randomizer.WritePanelData<float>(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f}); 92 WritePanelData<float>(shadowsPanels[randomOrder[0]], POWER, {1.0f, 1.0f});
105 93
106 /* Monastery 94 /* Monastery
107 randomOrder = std::vector(monasteryPanels.size(), 0); 95 randomOrder = std::vector(monasteryPanels.size(), 0);
diff --git a/Source/Randomizer.h b/Source/Randomizer.h index b644a1d..6615e31 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h
@@ -13,6 +13,8 @@ class Randomizer {
13public: 13public:
14 Randomizer(); 14 Randomizer();
15 15
16 void Randomize(int seed);
17
16 void Randomize(std::vector<int>& panels, int flags); 18 void Randomize(std::vector<int>& panels, int flags);
17 void RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex); 19 void RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex);
18 void SwapPanels(int panel1, int panel2, int flags); 20 void SwapPanels(int panel1, int panel2, int flags);
diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index 8a6c8eb..55d54d9 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj
@@ -46,7 +46,7 @@
46 <CharacterSet>Unicode</CharacterSet> 46 <CharacterSet>Unicode</CharacterSet>
47 </PropertyGroup> 47 </PropertyGroup>
48 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> 48 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49 <ConfigurationType>StaticLibrary</ConfigurationType> 49 <ConfigurationType>Application</ConfigurationType>
50 <UseDebugLibraries>false</UseDebugLibraries> 50 <UseDebugLibraries>false</UseDebugLibraries>
51 <PlatformToolset>v141</PlatformToolset> 51 <PlatformToolset>v141</PlatformToolset>
52 <WholeProgramOptimization>true</WholeProgramOptimization> 52 <WholeProgramOptimization>true</WholeProgramOptimization>
@@ -153,7 +153,6 @@
153 <ClInclude Include="Panels.h" /> 153 <ClInclude Include="Panels.h" />
154 <ClInclude Include="Randomizer.h" /> 154 <ClInclude Include="Randomizer.h" />
155 <ClInclude Include="Resource.h" /> 155 <ClInclude Include="Resource.h" />
156 <ClInclude Include="Main.h" />
157 <ClInclude Include="stdafx.h" /> 156 <ClInclude Include="stdafx.h" />
158 <ClInclude Include="targetver.h" /> 157 <ClInclude Include="targetver.h" />
159 </ItemGroup> 158 </ItemGroup>
diff --git a/Source/Source.vcxproj.filters b/Source/Source.vcxproj.filters index aad417a..b650d44 100644 --- a/Source/Source.vcxproj.filters +++ b/Source/Source.vcxproj.filters
@@ -24,9 +24,6 @@
24 <ClInclude Include="Resource.h"> 24 <ClInclude Include="Resource.h">
25 <Filter>Header Files</Filter> 25 <Filter>Header Files</Filter>
26 </ClInclude> 26 </ClInclude>
27 <ClInclude Include="Main.h">
28 <Filter>Header Files</Filter>
29 </ClInclude>
30 <ClInclude Include="Memory.h"> 27 <ClInclude Include="Memory.h">
31 <Filter>Header Files</Filter> 28 <Filter>Header Files</Filter>
32 </ClInclude> 29 </ClInclude>