//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * Lamp実装
 * @author Junpee
 */

#include "LampBasic.h"
#include "Core/System/LampCore.h"
#include "Graphics/System/LampGraphics.h"
#include "Input/System/LampInput.h"
#include "Core/Utility/Timer.h"
#include "Core/Thread/Thread.h"

namespace Lamp{

// 初期化フラグ
bool LampCore::isInitialized_ = false;

//------------------------------------------------------------------------------
// 初期化
void LampCore::initialize(){
	// 初期化済みなら無視する
	if(isInitialized_){ return; }
	// メモリ初期化
	MemoryChecker::initialize();
	// エラー出力初期化
//	ErrorOutInitialize();
	ErrorOutInitialize(NULL);
	// デバッグ出力初期化
	DebugOutInitialize();
	// スレッド初期化
	Thread::initialize();
	// タイマ初期化
	Timer::initialize();
	// 初期化フラグ立てる
	isInitialized_ = true;
}
//------------------------------------------------------------------------------
// 後始末
void LampCore::finalize(){
	// スレッド後始末
	Thread::finalize();
	// デバッグ出力後始末
	DebugOutFinalize();
	// エラー出力後始末
	ErrorOutFinalize();
	// 初期化フラグクリア
	isInitialized_ = false;
}
//------------------------------------------------------------------------------
// ウィンドウプロシージャ
LRESULT LampCore::windowProcedure(
	HWND windowHandle, u_int message, WPARAM wParam, LPARAM lParam){
	LRESULT result;
	// グラフィックスのプロシージャを呼ぶ
	result = LampGraphics::windowProcedure(
		windowHandle, message, wParam, lParam);
	if(result != 0){ return result; }

	// 入力のプロシージャを呼ぶ
	result = LampInput::windowProcedure(
		windowHandle, message, wParam, lParam);
	if(result != 0){ return result; }

	// メッセージの処理
	switch(message){
	// アプリケーション終了
	case WM_CLOSE:
		PostQuitMessage(0);
		break;
	}
	return 0;
}
//------------------------------------------------------------------------------
} // End of namespace Lamp
//------------------------------------------------------------------------------
