removing Halibut Engine

This commit is contained in:
Vladislav Khorev 2013-01-28 06:05:00 +00:00
parent cda8e18889
commit 448b2dd6d9
9 changed files with 0 additions and 1241 deletions

View File

@ -2,20 +2,6 @@
#define ENGINE_H_INCLUDED
#ifdef TARGET_HALIBUT
#ifdef TARGET_WIN32
#define HALIBUT_WIN32
#endif
#ifdef TARGET_ANDROID
#define HALIBUT_ANDROID
#endif
#ifdef TARGET_IOS
#define HALIBUT_IOS
#endif
#endif
#ifdef TARGET_SALMON
#ifdef TARGET_WIN32
#define SALMON_WIN32
@ -34,24 +20,12 @@
#include "SalmonEngineWindows.h"
#endif
#ifdef HALIBUT_WIN32
#include "HalibutEngineWindows.h"
#endif
#ifdef SALMON_ANDROID
#include "SalmonEngineAndroid.h"
#endif
#ifdef HALIBUT_ANDROID
#include "HalibutEngineAndroid.h"
#endif
#ifdef SALMON_IOS
#include "include/SalmonEngineIos.h"
#endif
#ifdef HALIBUT_IOS
#include "include/HalibutEngineIos.h"
#endif
#endif //ENGINE_H_INCLUDED

View File

@ -1,48 +0,0 @@
#ifndef HALIBUT_ENGINE_ANDROID_H_INCLUDED
#define HALIBUT_ENGINE_ANDROID_H_INCLUDED
#include "include/Utils/Utils.h"
#include "include/Utils/Console/console.h"
#include "include/Render/HalibutRender/HalibutRenderAndroid.h"
#include "include/HalibutEngineInterface.h"
//Android code only
namespace SE
{
extern TJavaConsole* Console;
extern THalibutResourceManager* ResourceManager;
extern THalibutRendererAndroid* Renderer;
class TApplication : public TApplicationAncestor
{
protected:
public:
TApplication();
virtual ~TApplication();
virtual void OuterInit(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight);
virtual void OuterDeinit();
virtual void OnKeyPress(cardinal key);
};
} //namespace SE
//This file includes templates that call any of three singletones: Console, ResourceManager or Renderer
#include "include/GUIManager/WidgetTemplatesImpl.h"
#endif

View File

@ -1,104 +0,0 @@
#ifndef HALIBUT_ENGINE_INTERFACE_H_INCLUDED
#define HALIBUT_ENGINE_INTERFACE_H_INCLUDED
#include "include/ApplicationInterface.h"
#include "include/TextureManager/SalmonTexture.h"
#include "include/ShaderManager/ShaderManager.h"
#include "include/ScriptManager/ScriptManager.h"
#include "include/GUIManager/GUIManager.h"
#include "include/FrameManager/FrameManager.h"
#include "include/FontManager/FontManager.h"
#include "include/HalibutAnimation/HalibutAnimation.h"
#include "include/SmartValueManager/SmartValueManager.h"
#ifdef TARGET_WIN32
#include "include/SoundManager/SoundManagerWindows.h"
#endif
#ifdef TARGET_ANDROID
#include "include/SoundManager/SoundManagerAndroid.h"
#endif
#ifdef TARGET_IOS
#include "include/SoundManager/SoundManagerIos.h"
#endif
namespace SE
{
//Windows only
struct TMouseState
{
int X;
int Y;
bool LeftButtonPressed;
bool MiddleButtonPressed;
bool RightButtonPressed;
};
class THalibutResourceManager
{
public:
std::string PathToResources;
TTextureListClass TexList;
TShaderManager ShaderManager;
TScriptManager ScriptManager;
TGUIManager GUIManager;
TFrameManager FrameManager;
TFontManager FontManager;
THalibutAnimationManager HalibutAnimationManager;
TSmartValueManager SmartValueManager;
#ifdef TARGET_WIN32
TSoundManagerWindows SoundManager;
#endif
#ifdef TARGET_ANDROID
TSoundManagerAndroid SoundManager;
#endif
#ifdef TARGET_IOS
TSoundManagerIos SoundManager;
#endif
};
class TApplicationAncestor : public TApplicationInterface
{
protected:
public:
TApplicationAncestor();
//If you override them, call ancestor:
virtual void OuterDraw();
virtual void OuterUpdate(cardinal dt);
virtual void OuterOnTapDown(vec2 p);
virtual void OuterOnTapUp(vec2 p);
virtual void OuterOnMove(vec2 shift);
virtual void InnerOnTapDown(vec2 p) { }
virtual void InnerOnTapUp(vec2 p) { }
virtual void InnerOnMove(vec2 shift) { }
virtual void OnFling(vec2 v) { } //Android only
virtual void OnMouseMove(TMouseState& mouseState) { } //Windows only
virtual void OnMouseWheel(short int delta) { } //Windows only
virtual void OnKeyPress(cardinal key) { } //Try not to override this. But if you need to override, call ancestor!
};
} //namespace SE
#endif

View File

@ -1,52 +0,0 @@
//
// HalibutEngineIos.h
// Halibut Engine
//
// Created by vvv ооо on 13.07.12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#ifndef HALIBUT_ENGINE_IOS_H_INCLUDED
#define HALIBUT_ENGINE_IOS_H_INCLUDED
#include "include/HalibutEngineInterface.h"
#include "include/Render/HalibutRender/HalibutRenderIos.h"
#include "include/Utils/Utils.h"
namespace SE
{
extern TIosConsole* Console;
extern THalibutResourceManager* ResourceManager;
extern THalibutRenderIos* Renderer;
class TApplication : public TApplicationAncestor
{
public:
TApplication();
virtual ~TApplication();
virtual void OuterInit(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight);
virtual void OuterDeinit();
virtual void OnKeyPress(cardinal key);
};
} //namespace SE
//This file includes templates that call any of three singletones: Console, ResourceManager or Renderer
#include "include/GUIManager/WidgetTemplatesImpl.h"
#endif

View File

@ -1,63 +0,0 @@
#pragma once //Windows ok
#include "include/Render/HalibutRender/HalibutRenderWindows.h"
#include "include/HalibutEngineInterface.h"
namespace SE
{
//==============================================================
//========= GLOBAL VARIABLES - REMEMBER THIS LIST!!! ===========
//==============================================================
extern HGLRC hRC; //Render context
extern HWND Hwnd; //Main window handle
extern HDC hDC; //Device context
extern TFileConsole* Console;
//Console and log for output
extern THalibutRenderer* Renderer;
//OpenGL renderer
extern THalibutResourceManager* ResourceManager;
//Resource Manager
class TApplication : public TApplicationAncestor
{
protected:
std::string LogFilename; //Log file name
unsigned char KeyboardBuffer[256];
public:
int X, Y, Width, Height; //Window position and size
float MatrixWidth, MatrixHeight;
std::string WindowName; //Window name
TApplication();
virtual ~TApplication();
const std::string& GetLogFilename();
char GetKeyState(cardinal keyNum);
void SetKeyboardBuffer(const unsigned char* source);
virtual void OnKeyPress(cardinal key); // If you override this, call ancestor!
};
int MainLoop(TApplication& application);
} //namespace SE
//This file includes templates that call any of three singletones: Console, ResourceManager or Renderer
#include "include/GUIManager/WidgetTemplatesImpl.h"

View File

@ -1,175 +0,0 @@
#include "include/HalibutEngineAndroid.h"
namespace SE
{
TJavaConsole* Console = NULL;
THalibutResourceManager* ResourceManager = NULL;
THalibutRendererAndroid* Renderer = NULL;
TApplication::TApplication()
{
}
void TApplication::OuterInit(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight)
{
OuterDeinit();
Console = new TJavaConsole;
*Console<<std::string("Console successfully started!!!");
ResourceManager = new THalibutResourceManager;
Renderer = new THalibutRendererAndroid;
ResourceManager->ScriptManager.BindBasicFunctions();
InnerInit();
Renderer->InitOpenGL(screenWidth, screenHeight, matrixWidth, matrixHeight);
}
void TApplication::OuterDeinit()
{
if (Console != NULL)
{
*Console<<"OuterDeinit";
}
InnerDeinit();
if (ResourceManager != NULL)
{
delete ResourceManager;
ResourceManager = NULL;
}
if (Renderer != NULL)
{
delete Renderer;
Renderer = NULL;
}
if (Console != NULL)
{
delete Console;
Console = NULL;
}
}
TApplication::~TApplication()
{
OuterDeinit();
}
void TApplication::OnKeyPress(cardinal key)
{
//For Android
//7-16 => "0".."9"
//29-54 => "a".."z"
//
if (IsConsoleOut)
{
if (key == 96 || key == 126) //` or ~
{
IsConsoleOut = false;
}
else if (key == 8) //Backspace
{
if (Console->ConsoleInput.size() > 0 && Console->ConsoleCursor > 0)
{
//Console->ConsoleInput.erase(Console->ConsoleInput.end()-1);
Console->ConsoleInput.erase(Console->ConsoleInput.begin() + Console->ConsoleCursor-1);
Console->ConsoleCursor--;
}
}
else if (key == 13 || key == 10) //Enter
{
ResourceManager->ScriptManager.RunScript(Console->ConsoleInput);
*Console<<"===>"+Console->ConsoleInput+"<===";
Console->InputHistory.push_back(Console->ConsoleInput);
Console->InputHistoryCursor = Console->InputHistory.size();
Console->ConsoleInput = "";
Console->ConsoleCursor = 0;
}
else if (key >= 32 && key <= 255) //ASCII
{
//Console->ConsoleInput += static_cast<char>(key);
Console->ConsoleInput.insert(Console->ConsoleInput.begin()+Console->ConsoleCursor, static_cast<char>(key));
Console->ConsoleCursor++;
}
else if (key > 0x100) //VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT
{
/*
cardinal realKey = key - 0x100;
if (realKey == VK_UP)
{
if (Console->InputHistoryCursor > 0)
{
Console->InputHistoryCursor--;
Console->ConsoleInput = Console->InputHistory[Console->InputHistoryCursor];
Console->ConsoleCursor = Console->ConsoleInput.size();
}
}
if (realKey == VK_DOWN)
{
if ( Console->InputHistoryCursor+1 < Console->InputHistory.size())
{
Console->InputHistoryCursor++;
Console->ConsoleInput = Console->InputHistory[Console->InputHistoryCursor];
Console->ConsoleCursor = Console->ConsoleInput.size();
}
}
if (realKey == VK_LEFT)
{
if (Console->ConsoleCursor > 0)
{
Console->ConsoleCursor--;
}
}
if (realKey == VK_RIGHT)
{
if (Console->ConsoleCursor < Console->ConsoleInput.size())
{
Console->ConsoleCursor++;
}
}*/
}
else
{
*Console<<std::string("Key is ")+tostr(key);
}
}
else
{
if (key == 96 || key == 126) //~
{
IsConsoleOut = true;
Console->ConsoleInput = "";
Console->ConsoleCursor = Console->ConsoleInput.size();
}
}
}
} //namespace SE

View File

@ -1,76 +0,0 @@
#include "include/HalibutEngineInterface.h"
#include "include/Engine.h"
namespace SE
{
TApplicationAncestor::TApplicationAncestor()
{
}
void TApplicationAncestor::OuterDraw()
{
CheckGlError("THalibutApplicationInterface::OuterDraw 1");
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0);
RenderUniform1i("Texture", 0);
RenderUniform1f("Transparency", 1.f);
InnerDraw();
CheckGlError("THalibutApplicationInterface::OuterDraw 1.5");
ResourceManager->GUIManager.Draw();
if (IsConsoleOut)
{
Console->Draw();
}
CheckGlError("THalibutApplicationInterface::OuterDraw 2");
}
void TApplicationAncestor::OuterUpdate(cardinal dt)
{
CheckGlError();
ResourceManager->GUIManager.Update(dt);
ResourceManager->HalibutAnimationManager.Update(dt);
#ifndef TARGET_IOS
ResourceManager->SoundManager.Update(dt);
#endif
CheckGlError();
InnerUpdate(dt);
CheckGlError();
}
void TApplicationAncestor::OuterOnTapDown(vec2 p)
{
ResourceManager->GUIManager.OnMouseDown(p);
InnerOnTapDown(p);
}
void TApplicationAncestor::OuterOnTapUp(vec2 p)
{
ResourceManager->GUIManager.OnMouseUp(p);
InnerOnTapUp(p);
}
void TApplicationAncestor::OuterOnMove(vec2 shift)
{
ResourceManager->GUIManager.OnMove(shift);
InnerOnMove(shift);
}
} //namespace SE

View File

@ -1,187 +0,0 @@
//
// HalibutEngineIos.cpp
// Halibut Engine
//
// Created by vvv ооо on 13.07.12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include "include/Engine.h"
#include "include/HalibutEngineIos.h"
namespace SE
{
TIosConsole* Console = NULL;
THalibutResourceManager* ResourceManager = NULL;
THalibutRenderIos* Renderer = NULL;
TApplication::TApplication()
{
}
void TApplication::OuterInit(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight)
{
OuterDeinit();
Console = new TIosConsole;
*Console<<std::string("Console successfully started!!!");
ResourceManager = new THalibutResourceManager;
Renderer = new THalibutRenderIos;
ResourceManager->ScriptManager.BindBasicFunctions();
InnerInit();
Renderer->InitOpenGL(screenWidth, screenHeight, matrixWidth, matrixHeight);
}
void TApplication::OuterDeinit()
{
if (Console != NULL)
{
*Console<<"OuterDeinit";
}
InnerDeinit();
if (ResourceManager != NULL)
{
delete ResourceManager;
ResourceManager = NULL;
}
if (Renderer != NULL)
{
delete Renderer;
Renderer = NULL;
}
if (Console != NULL)
{
delete Console;
Console = NULL;
}
}
TApplication::~TApplication()
{
OuterDeinit();
}
void TApplication::OnKeyPress(cardinal key)
{
//For Android
//7-16 => "0".."9"
//29-54 => "a".."z"
//
if (IsConsoleOut)
{
if (key == 96 || key == 126) //` or ~
{
IsConsoleOut = false;
}
else if (key == 8) //Backspace
{
if (Console->ConsoleInput.size() > 0 && Console->ConsoleCursor > 0)
{
//Console->ConsoleInput.erase(Console->ConsoleInput.end()-1);
Console->ConsoleInput.erase(Console->ConsoleInput.begin() + Console->ConsoleCursor-1);
Console->ConsoleCursor--;
}
}
else if (key == 13 || key == 10) //Enter
{
ResourceManager->ScriptManager.RunScript(Console->ConsoleInput);
*Console<<"===>"+Console->ConsoleInput+"<===";
Console->InputHistory.push_back(Console->ConsoleInput);
Console->InputHistoryCursor = Console->InputHistory.size();
Console->ConsoleInput = "";
Console->ConsoleCursor = 0;
}
else if (key >= 32 && key <= 255) //ASCII
{
//Console->ConsoleInput += static_cast<char>(key);
Console->ConsoleInput.insert(Console->ConsoleInput.begin()+Console->ConsoleCursor, static_cast<char>(key));
Console->ConsoleCursor++;
}
else if (key > 0x100) //VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT
{
/*
cardinal realKey = key - 0x100;
if (realKey == VK_UP)
{
if (Console->InputHistoryCursor > 0)
{
Console->InputHistoryCursor--;
Console->ConsoleInput = Console->InputHistory[Console->InputHistoryCursor];
Console->ConsoleCursor = Console->ConsoleInput.size();
}
}
if (realKey == VK_DOWN)
{
if ( Console->InputHistoryCursor+1 < Console->InputHistory.size())
{
Console->InputHistoryCursor++;
Console->ConsoleInput = Console->InputHistory[Console->InputHistoryCursor];
Console->ConsoleCursor = Console->ConsoleInput.size();
}
}
if (realKey == VK_LEFT)
{
if (Console->ConsoleCursor > 0)
{
Console->ConsoleCursor--;
}
}
if (realKey == VK_RIGHT)
{
if (Console->ConsoleCursor < Console->ConsoleInput.size())
{
Console->ConsoleCursor++;
}
}*/
}
else
{
*Console<<std::string("Key is ")+tostr(key);
}
}
else
{
if (key == 96 || key == 126) //~
{
IsConsoleOut = true;
Console->ConsoleInput = "";
Console->ConsoleCursor = Console->ConsoleInput.size();
}
}
}
} //namespace SE

View File

@ -1,510 +0,0 @@
#include "include/Utils/Utils.h"
#include "include/HalibutEngineWindows.h"
namespace SE
{
//==============================================================
//========= GLOBAL VARIABLES - REMEMBER THIS LIST!!! ===========
//==============================================================
HGLRC hRC; //Render context
HWND Hwnd; //Main window handle
HDC hDC; //Device context
TFileConsole* Console = NULL;
THalibutRenderer* Renderer = NULL;
THalibutResourceManager* ResourceManager = NULL;
//==============================================================
//=============== GLOBAL VARS ENDS =============================
//==============================================================
const int CONST_DEFAULT_SCREEN_WIDTH = 800;
const int CONST_DEFAULT_SCREEN_HEIGHT = 600;
const cardinal CONST_TIMER_INTERVAL = 10;
//There might be anything
const char CONST_WINDOW_CLASS_NAME[] = "TSalmonEngineForm";
//To calculate when to call Update
cardinal NewTickCount;
cardinal LastTickCount;
vec2 MouseButtonPos;
vec2 MouseTotalShift;
bool MouseButtonPressed = false;
bool MouseMoved = false;
//User application
TApplication* App = NULL;
TApplication::TApplication()
: X(0)
, Y(0)
, Width(800)
, Height(600)
, MatrixWidth(0.f)
, MatrixHeight(0.f)
, WindowName("Halibut Engine")
, LogFilename("log.txt")
{
for(int i=0; i<256; i++)
{
KeyboardBuffer[i] = 0;
}
}
TApplication::~TApplication()
{
}
const std::string& TApplication::GetLogFilename()
{
return LogFilename;
}
char TApplication::GetKeyState(cardinal keyNum)
{
if (keyNum > 255)
throw ErrorToLog("GetKeyState - invalid key number!");
return KeyboardBuffer[keyNum];
}
void TApplication::SetKeyboardBuffer(const unsigned char* source)
{
memcpy((unsigned char*)KeyboardBuffer, source, 256);
}
void TApplication::OnKeyPress(cardinal key)
{
if (IsConsoleOut)
{
if (key == 96 || key == 126) //~
{
IsConsoleOut = false;
}
else if (key == 8) //Backspace
{
if (Console->ConsoleInput.size() > 0 && Console->ConsoleCursor > 0)
{
Console->ConsoleInput.erase(Console->ConsoleInput.begin() + Console->ConsoleCursor-1);
Console->ConsoleCursor--;
}
}
else if (key == 13|| key == 10) //Enter
{
ResourceManager->ScriptManager.RunScript(Console->ConsoleInput);
Console->InputHistory.push_back(Console->ConsoleInput);
Console->InputHistoryCursor = Console->InputHistory.size();
Console->ConsoleInput = "";
Console->ConsoleCursor = 0;
}
else if (key >= 32 && key <= 255) //ASCII
{
Console->ConsoleInput.insert(Console->ConsoleInput.begin()+Console->ConsoleCursor, static_cast<char>(key));
Console->ConsoleCursor++;
}
else if (key > 0x100) //VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT
{
cardinal realKey = key - 0x100;
if (realKey == VK_UP)
{
if (Console->InputHistoryCursor > 0)
{
Console->InputHistoryCursor--;
Console->ConsoleInput = Console->InputHistory[Console->InputHistoryCursor];
Console->ConsoleCursor = Console->ConsoleInput.size();
}
}
if (realKey == VK_DOWN)
{
if ( Console->InputHistoryCursor+1 < Console->InputHistory.size())
{
Console->InputHistoryCursor++;
Console->ConsoleInput = Console->InputHistory[Console->InputHistoryCursor];
Console->ConsoleCursor = Console->ConsoleInput.size();
}
}
if (realKey == VK_LEFT)
{
if (Console->ConsoleCursor > 0)
{
Console->ConsoleCursor--;
}
}
if (realKey == VK_RIGHT)
{
if (Console->ConsoleCursor < Console->ConsoleInput.size())
{
Console->ConsoleCursor++;
}
}
}
else
{
*Console<<"Key is "+tostr(key)+endl;
}
}
else
{
ResourceManager->GUIManager.KeyPressedSignal(key);
if (key == 96 || key == 126) //~
{
IsConsoleOut = true;
Console->ConsoleInput = "";
Console->ConsoleCursor = Console->ConsoleInput.size();
}
}
}
void DrawScene()
{
App->OuterDraw();
SwapBuffers(hDC);
}
void ProcessTickCount()
{
//unsigned char keyboardStateArr[256];
NewTickCount = GetTickCount();
if (NewTickCount - LastTickCount > CONST_TIMER_INTERVAL)
{
/*
GetKeyboardState((unsigned char*)keyboardStateArr);
App->SetKeyboardBuffer((unsigned char*)keyboardStateArr);
*/
App->OuterUpdate(NewTickCount - LastTickCount);
LastTickCount = NewTickCount;
}
}
LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static PAINTSTRUCT ps;
TMouseState mouseState;
switch(uMsg)
{
case WM_CLOSE:
Hwnd = 0; //HACK to force window to close
PostQuitMessage(0);
//Xperimental
return DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
case WM_PAINT:
DrawScene();
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
ProcessTickCount();
break;
case WM_SIZE:
PostMessage(hWnd, WM_PAINT, 0, 0);
break;
case WM_CHAR:
App->OnKeyPress(wParam);
/*
switch (wParam)
{
case 27:
PostQuitMessage(0);
Hwnd = 0;
//Xperimental
return DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
//... Will add more code later
}
*/
break;
case WM_KEYDOWN:
//Special for arrow keys
if (wParam == VK_UP || wParam == VK_DOWN || wParam == VK_LEFT || wParam == VK_RIGHT)
{
App->OnKeyPress(0x100 + wParam);
}
break;
case WM_MOUSEMOVE:
mouseState.X = (lParam << 16) >> 16;
mouseState.Y = lParam >> 16;
mouseState.LeftButtonPressed = (wParam & MK_LBUTTON);
mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON);
mouseState.RightButtonPressed = (wParam & MK_RBUTTON);
App->OnMouseMove(mouseState);
if (MouseButtonPressed)
{
vec2 currentMousePos(static_cast<float>(mouseState.X), static_cast<float>(App->Height - mouseState.Y));
vec2 shift = (MouseButtonPos - currentMousePos);
//shift.v[1] = - shift.v[1];
App->OuterOnMove(shift);
//App->OuterOnMove(currentMousePos - MouseButtonPos);
MouseButtonPos = currentMousePos;
MouseTotalShift += shift;
if (fabs(MouseTotalShift.v[0]) > 10.f || fabs(MouseTotalShift.v[1]) > 10.f)
{
MouseMoved = true;
}
}
break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
mouseState.X = (lParam << 16) >> 16;
mouseState.Y = lParam >> 16;
mouseState.LeftButtonPressed = (wParam & MK_LBUTTON);
mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON);
mouseState.RightButtonPressed = (wParam & MK_RBUTTON);
MouseButtonPos = vec2(static_cast<float>(mouseState.X), static_cast<float>(App->Height - mouseState.Y));
if (mouseState.LeftButtonPressed)
{
App->OuterOnTapDown(MouseButtonPos);
}
MouseButtonPressed = true;
MouseMoved = false;
MouseTotalShift = vec2(0,0);
break;
case WM_LBUTTONUP:
case WM_RBUTTONUP:
mouseState.X = (lParam << 16) >> 16;
mouseState.Y = lParam >> 16;
mouseState.LeftButtonPressed = (wParam & MK_LBUTTON);
mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON);
mouseState.MiddleButtonPressed = (wParam & MK_RBUTTON);
if (!MouseMoved)
{
App->OuterOnTapUp(vec2(static_cast<float>(mouseState.X), static_cast<float>(App->Height - mouseState.Y)));
}
MouseButtonPressed = false;
break;
case WM_MOUSEWHEEL:
App->OnMouseWheel(wParam >> 16);
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
bool CreateOpenGLWindow(const char* title, int x, int y, int width, int height,HWND& hWnd, HDC& hDC, HGLRC& hRC)
{
int pf;
WNDCLASS wc;
PIXELFORMATDESCRIPTOR pfd;
static HINSTANCE hInstance = 0;
if (!hInstance)
{
hInstance = GetModuleHandle(NULL);
wc.style = CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = CONST_WINDOW_CLASS_NAME;
if (!RegisterClass(&wc))
{
return NULL;
}
}
RECT r;
r.left = x;
r.right = x + width;
r.top = y;
r.bottom = y + height;
DWORD windowStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
AdjustWindowRect(&r, windowStyle, false);
hWnd = CreateWindow(CONST_WINDOW_CLASS_NAME, title, windowStyle, 0, 0, r.right-r.left, r.bottom-r.top, NULL, NULL, hInstance, NULL);
if (hWnd == NULL)
{
return false;
}
hDC = GetDC(hWnd);
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pf = ChoosePixelFormat(hDC, &pfd);
if (pf == 0)
{
return false;
}
if (SetPixelFormat(hDC, pf, &pfd) == FALSE)
{
return false;
}
hRC = wglCreateContext( hDC );
wglMakeCurrent( hDC, hRC );
return true;
}
int MainLoop(TApplication& application)
{
MSG msg;
//Here console log is not created so we can not use ErrorCommon
try
{
Console = new TFileConsole(application.GetLogFilename());
}
catch(...)
{
exit(1);
}
//Here console log is already created
try
{
*Console<<"Log started";
if (!CreateOpenGLWindow(application.WindowName.c_str(), application.X, application.Y, application.Width, application.Height,Hwnd,hDC,hRC))
{
*Console<<"Unable to create OpenGL Window!";
exit(1);
}
*Console<<"OpenGL Window created";
if (App != NULL)
throw ErrorCommon();
App = &application;
Renderer = new THalibutRenderer;
ResourceManager = new THalibutResourceManager;
if (Renderer->BindOpenGLFunctions())
{
if (App->MatrixWidth == 0)
{
App->MatrixWidth = static_cast<float>(App->Width);
}
if (App->MatrixHeight == 0)
{
App->MatrixHeight = static_cast<float>(App->Height);
}
App->OuterInit(App->Width, App->Height, App->MatrixWidth, App->MatrixHeight);
ShowWindow(Hwnd, SW_SHOW);
UpdateWindow(Hwnd);
NewTickCount = GetTickCount();
LastTickCount = NewTickCount;
bool StayIn = true;
while (StayIn)
{
while(PeekMessage(&msg, Hwnd, 0, 0, PM_NOREMOVE))
{
if(GetMessage(&msg, Hwnd, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
StayIn = false;
}
}
DrawScene();
ProcessTickCount();
}
}
*Console<<"Program prepares to quit";
App->OuterDeinit();
delete ResourceManager;
delete Renderer;
wglMakeCurrent(NULL, NULL);
ReleaseDC(Hwnd,hDC);
wglDeleteContext(hRC);
DestroyWindow(Hwnd);
}
catch(ErrorCommon)
{
//... let the ErrorTypes.h do the buisness
}
delete Console;
return 0;
}
} //namespace SE