Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
eXpl0it3r committed Jan 15, 2015
2 parents c43119a + 954e168 commit 1c45b7b
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 274 deletions.
Binary file modified bin/images/Panel.bmp
Binary file not shown.
14 changes: 9 additions & 5 deletions build/Landscape.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@
<TreatWarningAsError>false</TreatWarningAsError>
<MinimalRebuild>true</MinimalRebuild>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>SFML_STATIC;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>.\Debug\</AssemblerListingLocation>
<BrowseInformation>true</BrowseInformation>
<PrecompiledHeaderOutputFile>.\Debug\Landscape.pch</PrecompiledHeaderOutputFile>
<ObjectFileName>.\Debug\</ObjectFileName>
<ProgramDataBaseFileName>.\Debug\</ProgramDataBaseFileName>
<AdditionalIncludeDirectories>..\extlibs\include</AdditionalIncludeDirectories>
</ClCompile>
<Midl>
<SuppressStartupBanner>true</SuppressStartupBanner>
Expand All @@ -141,9 +142,10 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OutputFile>.\Debug\Schiffbruch.exe</OutputFile>
<AdditionalDependencies>dsound.lib;winmm.lib;dxguid.lib;ddraw.lib;dinput.lib;xinput.lib;dinput8.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-window-s-d.lib;sfml-system-s-d.lib;opengl32.lib;gdi32.lib;dsound.lib;winmm.lib;dxguid.lib;ddraw.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86;..\extlibs\lib</AdditionalLibraryDirectories>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalOptions>/ignore:4204 %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -155,12 +157,13 @@
<Optimization>MaxSpeed</Optimization>
<SuppressStartupBanner>true</SuppressStartupBanner>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>SFML_STATIC;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>.\Release\</AssemblerListingLocation>
<BrowseInformation>true</BrowseInformation>
<PrecompiledHeaderOutputFile>.\Release\Landscape.pch</PrecompiledHeaderOutputFile>
<ObjectFileName>.\Release\</ObjectFileName>
<ProgramDataBaseFileName>.\Release\</ProgramDataBaseFileName>
<AdditionalIncludeDirectories>..\extlibs\include</AdditionalIncludeDirectories>
</ClCompile>
<Midl>
<SuppressStartupBanner>true</SuppressStartupBanner>
Expand All @@ -182,8 +185,9 @@
<SuppressStartupBanner>true</SuppressStartupBanner>
<SubSystem>Windows</SubSystem>
<OutputFile>.\Release\Schiffbruch.exe</OutputFile>
<AdditionalDependencies>dsound.lib;winmm.lib;dxguid.lib;ddraw.lib;dinput.lib;xinput.lib;dinput8.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>sfml-window-s.lib;sfml-system-s.lib;opengl32.lib;gdi32.lib;dsound.lib;winmm.lib;dxguid.lib;ddraw.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalLibraryDirectories>..\extlibs\lib</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
2 changes: 1 addition & 1 deletion src/Action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Action
DOCK = 14,
PIPE = 15,
DESTROY = 16,
SOS = 17,
SOS_SIGN = 17,
HOUSE1 = 18,
HOUSE2 = 19,
HOUSE3 = 20,
Expand Down
137 changes: 36 additions & 101 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,132 +16,67 @@
#include <exception>

Application::Application(const std::string& name, HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
: m_name(name)
: m_window({ MAXX, MAXY }, name, sf::Style::Fullscreen)
, m_name(name)
, m_hWnd(m_window.getSystemHandle())
, m_hInstance(hInstance)
, m_hPrevInstance(hPrevInstance)
, m_lpCmdLine(lpCmdLine)
, m_nCmdShow(nCmdShow)
{
// Set globals
g_hInst = m_hInstance;

if (!create_window())
throw std::runtime_error("Failed to create a valid window.");

hwnd = m_hWnd;

Direct::InitDInput();
MouseInit = true;

ShowWindow(m_hWnd, m_nCmdShow);
UpdateWindow(m_hWnd);

Direct::InitDDraw();
Direct::InitDSound();

SetTimer(hwnd, 0, 1000, nullptr); // Provisorisch
srand((unsigned)time(nullptr)); // Random initialisieren
}

LRESULT CALLBACK Application::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
void Application::process_events()
{
Application* pApp = nullptr;

if (uMsg == WM_NCCREATE)
sf::Event event;
while (m_window.pollEvent(event))
{
// Get the pointer to the window from lpCreateParams which was set in create_window
SetWindowLong(hWnd, GWL_USERDATA, (long)((LPCREATESTRUCT(lParam))->lpCreateParams));
if (event.type == sf::Event::Closed)
{
Direct::finiObjects();
m_window.close();
}
else if (event.type == sf::Event::GainedFocus)
{
bActive = TRUE;
}
else if (event.type == sf::Event::KeyReleased)
{
if (event.key.code == sf::Keyboard::F4)
{
Direct::finiObjects();
m_window.close();
}
}
}

// Get the pointer to the application
pApp = Application::ptr(hWnd);

// If we have the pointer, go to the message handler of the window else, use DefWindowProc
if (pApp)
return pApp->process_events(hWnd, uMsg, wParam, lParam);
else
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

LRESULT CALLBACK Application::process_events(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
int Application::run()
{
m_hWnd = hWnd;

static BYTE phase = 0;
sf::Clock timer;

switch (uMsg)
while (m_window.isOpen())
{
case WM_ACTIVATEAPP:
bActive = wParam;
Direct::SetAcquire();
break;

case WM_ACTIVATE: // Sent when window changes active state
bActive = wParam;
Direct::SetAcquire();
break;
process_events();

case WM_CREATE:
break;

case WM_TIMER:
if (Refresh() == 0)
PostMessage(hwnd, WM_DESTROY, 0, 0);
break;

case WM_QUIT:
case WM_DESTROY:
Direct::finiObjects();
PostQuitMessage(0);
break;
}

return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

bool Application::create_window()
{
WNDCLASS wc;

// Set up and register window class
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = &Application::WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = m_hInstance;
wc.hIcon = LoadIcon(m_hInstance, IDI_APPLICATION);
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hbrBackground = nullptr;
wc.lpszMenuName = m_name.c_str();
wc.lpszClassName = m_name.c_str();
RegisterClass(&wc);

// Create a window
m_hWnd = CreateWindowEx(
WS_EX_TOPMOST,
m_name.c_str(),
m_name.c_str(),
WS_POPUP,
0,
0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
NULL,
NULL,
m_hInstance,
this);

return m_hWnd != nullptr;
}
if (timer.getElapsedTime() > sf::milliseconds(1000))
{
if (Refresh() == 0)
m_window.close();

int Application::run()
{
while (GetMessage(&m_msg, nullptr, 0, 0))
{
TranslateMessage(&m_msg);
DispatchMessage(&m_msg);
timer.restart();
}
}

return m_msg.wParam;
return 0;
}

short Application::Refresh()
Expand Down Expand Up @@ -278,7 +213,7 @@ void Application::Event(short Eventnr)
case Action::DESTROY:
Action::destroy();
break;
case Action::SOS:
case Action::SOS_SIGN:
Action::sos();
break;
case Action::HOUSE1:
Expand Down
14 changes: 5 additions & 9 deletions src/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "headers.hpp"
#include "extern.hpp"

#include <SFML/Window.hpp>

#include <string>

class Application
Expand All @@ -20,17 +22,11 @@ class Application
BOOL doInit();

private:
LRESULT CALLBACK process_events(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

bool create_window();

// Returns a pointer the application (stored as the WindowLong)
inline static Application *ptr(HWND hWnd)
{
return (Application *)GetWindowLong(hWnd, GWL_USERDATA);
}
void process_events();

private:
sf::Window m_window;

std::string m_name;
MSG m_msg;
HWND m_hWnd;
Expand Down
Loading

0 comments on commit 1c45b7b

Please sign in to comment.