Files
LifeProject/MyGame/include/MyGame.h
T
2025-05-13 02:46:21 +03:00

382 lines
12 KiB
C++

#ifndef MyGame_h__
#define MyGame_h__
#include "Game.h"
#include "Actor.h"
#include <Player.h>
#include "InputSystemOIS.h"
#include "states/StateGame.h"
#include <states/StateSettings.h>
#include "EntityFactory.h"
#include "gui/GUIButton.h"
#include "gui/GUIText.h"
#include "gui/GUITextInput.h"
#include "gui/GUIFont.h"
#include "Spectator.h"
static const Vec3f colors[6] =
{
Vec3f(0,1,0),
Vec3f(1, 0, 1),
Vec3f(1, 0, 0),
Vec3f(0,0,1),
Vec3f(1,1,0),
Vec3f(1,1,1)
};
class MyGame : public Game
{
public:
Light* l;
Light* l2;
Light* l3;
MyGame()
{
}
~MyGame()
{
}
void Load(int _mainWindow, IRenderWindow* _outWindow)
{
if(_mainWindow)
{
customWindow = true;
output = _outWindow;
mainWindow = _mainWindow;
}
Video::Timer t;
Camera cam;
cam.setPosition(Vec3f(0.0f,0.0f,0.0f));
cam.setDirection(Vec3f(-100.0f,0.0f,0.0f));
Matrix4x4 v = cam.getView();
Vec3f vector(0.0f, 10.0f, 10.0f);
Vec3f rs;
Vec3TransformCoordinate(vector, v, rs);
Range<unsigned long> r(0x0410, 0x04ff);
// GUIFont* fnt = new GUIFont(&r,1);
//CLog::me()->LogToConsole(true);
//CLog::me()->Write(AS_STRING("Creating new game"));
//SetResourcesPath(AS_STRING("C:\\development\\Programming\\Projects\\Data\\"));
//IPakFileContentProvider pp( _text("C:\\Data.pak"));
//IPakFileContentProvider pp( _text("Data.pak"));
//String mp(_text("root"));
//ResourceManager::me()->MountContentProvider(&pp, mp);
t.Start();
if(!customWindow)
{
SetWindow(1200, 700);
mainWindow = output->GetWindowHandle();
}
GetWindow()->SetCaption(STR("Crysis 4. DirectX11. over9000 fps"));
t.Stop();
printf("Window creation: %f\n", t.getTimeElapsed());
t.Start();
InitVideo(RT_DIRECTX_11);
t.Stop();
printf("Video creation: %f\n", t.getTimeElapsed());
t.Start();
InitInput();
t.Stop();
printf("Input creation: %f\n", t.getTimeElapsed());
gameWorld = new World(this, pGraphics->GetSceneManager()->GetActiveScene(), physicsWorld);
/*int modeCount = GetGraphics()->GetMainRenderer()->GetDisplayModes(&modes);
for(int i = 0; i < modeCount; i++)
{
printf("Mode ID: %i\n", i);
printf("Mode width: %i\n", modes[i].width);
printf("Mode height: %i\n", modes[i].height);
printf("Mode rate: %i\n", modes[i].refreshRate);
}*/
t.Start();
int ci = 0;
/*float fieldSize = 3.5f;
int cnt = 4;
Vec3f offset(-fieldSize/2.0f,1.05f, fieldSize / 2.0f);
float step = fieldSize / (float)cnt;*/
/*for(int z = 0; z < cnt; z++)
{
for(int x = 0; x < cnt; x++)
{
Light* l = pGraphics->GetResourceManager()->CreatePointLight(offset + Vec3f(step * (float)x, 0, -step * float(z)), 4.35f);
l->color = colors[ci];
l->intensity = 2.0f;
l->specularPower = 28.0f;
pGraphics->GetSceneManager()->GetActiveScene()->PushNode(l);
//Light* l = pGraphics->GetResourceManager()->CreateSpotLight(offset + Vec3f(step * (float)x, 0, -step * (float)z),offset + Vec3f(step * (float)x, -1.0f, -step * (float)z),5.0f,1.0f, 1.2f);
//l->color = colors[ci];
//l->intensity = 2.0f;
//l->specularPower = 28.0f;
//l->castShadows = false;
//pGraphics->GetSceneManager()->GetActiveScene()->PushNode(l);
ci++;
if(ci>=6) ci = 0;
}
}*/
/*
l2 = pGraphics->GetResourceManager()->CreatePointLight(Vec3f(0.5f,0.4f,0), 3.0f);
l2->color = colors[2];
l2->intensity = 1.0f;
l2->specularPower = 28.0f;
l2->castShadows = true;
pGraphics->GetSceneManager()->GetActiveScene()->PushNode(l2);
l3 = pGraphics->GetResourceManager()->CreatePointLight(Vec3f(1.5f,0.4f,0), 3.0f);
l3->color = colors[3];
l3->intensity = 1.0f;
l3->specularPower = 28.0f;
l3->castShadows = true;
pGraphics->GetSceneManager()->GetActiveScene()->PushNode(l3);
*/
l = pGraphics->GetResourceManager()->CreatePointLight(Vec3f(0.0f,0.4f,0), 3.0f);
l->color = colors[0];
l->intensity = 1.0f;
l->specularPower = 28.0f;
l->castShadows = true;
pGraphics->GetSceneManager()->GetActiveScene()->PushNode(l);
Light* l2 = pGraphics->GetResourceManager()->CreateSpotLight(Vec3f(0.2f,1.0f,0.0f),Vec3f(0.0f,0.5f,1.6f),5.0f,1.3f, 1.40f);
l2->color = Vec3f(1.0f,1.0f,1.0f);
l2->intensity = 1.0f;
l2->specularPower = 28.0f;
l2->castShadows = true;
pGraphics->GetSceneManager()->GetActiveScene()->PushNode(l2);
t.Stop();
printf("Light creation: %f\n", t.getTimeElapsed());
IMaterial* mat2 = new IMaterial();
mat2->castShadows = false;
mat2->shininess = 0.3f;
mat2->specularPower = 20.0f;
mat2->normalMapping = true;
mat2->diffuseMap = ResourceManager::me()->GetTexture("root/Data/Textures/Rock/rock.jpg");
mat2->normalMap = ResourceManager::me()->GetTexture("root/Data/Textures/Rock/rockNormal.jpg");
Entity* floor = new Entity();
IGraphicsEntity* floorVisual = new IGraphicsEntity(GetGraphics());
IMesh* mesh = ResourceManager::me()->GetMesh("root/Data/Objects/House_opt.vmf");
IObjectMesh* go = new IObjectMesh(mesh);
IMaterial* mat = new IMaterial();
mat->castShadows = false;
mat->shininess = 1;
mat->specularPower = 50.0f;
mat->normalMapping = true;
mat->diffuseMap = ResourceManager::me()->GetTexture("root/Data/Textures/basic_floor_s.BMP");
mat->normalMap = ResourceManager::me()->GetTexture("root/Data/Textures/basic_floor_s_ddn.BMP");
go->setMaterial(mat, 0);
floorVisual->SetBody(go);
floor->SetGraphicalEntity(floorVisual);
IPhysicsEntity* pe = new IPhysicsEntity(floor);
pe->CreateRigidBodyPhysics(Vec3f(0, 0, 0), go->getBoundingBox(), 0, NULL);
floor->SetPhysicsEntity(pe);
gameWorld->AddEntity(floor);
float fieldSize = 3.5f;
int cnt = 4;
Vec3f offset(-fieldSize/2.0f,1.05f, fieldSize / 2.0f);
float step = fieldSize / (float)cnt;
for(int z = 0; z < cnt; z++)
{
for(int x = 0; x < cnt; x++)
{
Entity* thing = new Entity();
IGraphicsEntity* thingVisual = new IGraphicsEntity(GetGraphics());
thingVisual->Load("root/Data/Objects/Tower_opt.vmf");
thingVisual->GetBody()->setMaterial(mat2, 0);
thing->SetGraphicalEntity(thingVisual);
IPhysicsEntity* pe2 = new IPhysicsEntity(thing);
pe2->CreateRigidBodyPhysics(Vec3f(0, 0, 0), thingVisual->GetBody()->getBoundingBox(), 0, NULL);
thing->SetPhysicsEntity(pe2);
gameWorld->AddEntity(thing);
thing->GetTransform()->SetPosition(Vec3f((float)x * step - 0.8f,0.2f,(float)z*step -1.5f));
}
}
/*
Light* l = pGraphics->GetResourceManager()->CreateSpotLight(Vec3f(1.2f,2.2f,1.2f),Vec3f(1.4f,0.0f,1.4f),5.0f,1.3f, 1.99f);
l->color = Vec3f(1.0f,1.0f,1.0f);
l->intensity = 1.0f;
l->specularPower = 28.0f;
l->castShadows = true;
pGraphics->GetSceneManager()->GetActiveScene()->PushNode(l);*/
/*Light* l2 = pGraphics->GetResourceManager()->CreateSpotLight(Vec3f(-1.6f,2.2f,0.4f),Vec3f(-1.6f,0.0f,0.4f),4.0f,1.0f, 1.5f);
l2->color = Vec3f(0.0f,0.0f,1.0f);
l2->intensity = 2.0f;
l2->specularPower = 28.0f;
l2->castShadows = false;
pGraphics->GetSceneManager()->GetActiveScene()->PushNode(l2);*/
/*player = (Player*)EntityFactory::me()->BuildEntity(AS_STRING("root/Data/Entities/thing.xml"), this);
player->GetTransform()->SetPosition(Vec3f(0.3f,0.5f,0.2f));
player->GetTransform()->SetRotation(Vec3f(0.0f,1.0f,0.0f), 1.0f);
player->GetGraphicalEntity()->pMesh->getMaterial(0)->shininess = 0.5f;
player->GetGraphicalEntity()->pMesh->getMaterial(0)->specularPower = 15.0f;*/
/*t.Start();
Entity* hall = EntityFactory::me()->BuildEntity(AS_STRING("root/Data/Entities/level_0_p0.xml"), this);
gameWorld->AddEntity(hall);
t.Stop();
printf("Hall creation: %f\n", t.getTimeElapsed());
t.Start();
Entity* crate = EntityFactory::me()->BuildEntity(AS_STRING("root/Data/Entities/crate_small.xml"), this);
crate->GetTransform()->SetPosition(Vec3f(-1.0f, 0.8f, 0.0f));
gameWorld->AddEntity(crate);
t.Stop();
printf("Crate creation: %f\n", t.getTimeElapsed());
t.Start();
Entity* tv = EntityFactory::me()->BuildEntity(AS_STRING("root/Data/Entities/tv_flat.xml"), this);
tv->GetTransform()->SetPosition(Vec3f(-4.0f, 1.6f, -1.4f));
tv->GetTransform()->SetRotation(Vec3f(0.0f,1.0f,0.0f), 3.1415926535f);
gameWorld->AddEntity(tv);
t.Stop();
printf("TV creation: %f\n", t.getTimeElapsed());*/
//miranda->Save();
StateGame* gs = new StateGame(AS_STRING("gameplay"), this);
stateManager.AddState(gs->GetName(), gs);
StateSettings* sm = new StateSettings("settings_menu", this);
stateManager.AddState(sm->GetName(), sm);
actionMap.MapAction(ACTION_FORWARD, KEY_W);
actionMap.MapAction(ACTION_BACKWARD, KEY_S);
actionMap.MapAction(ACTION_LEFT, KEY_A);
actionMap.MapAction(ACTION_RIGHT, KEY_D);
actionMap.MapAction(ACTION_JUMP, KEY_SPACE);
actionMap.MapAction(ACTION_ACCELERATION, KEY_LSHIFT);
actionMap.MapAction(ACTION_FIRE, KEY_MOUSE_LEFT);
actionMap.MapAction(ACTION_USE, KEY_F);
actionMap.MapAction(ACTION_TURNLR, KEY_AXIS_X);
actionMap.MapAction(ACTION_TURNUD, KEY_AXIS_Y);
//Spectator* sp = new Spectator(this);
//sp->GetTransform()->SetPosition(Vec3f(0,1,0));
Player* p = new Player(this);
gameWorld->AddEntity(p);
SetPlayer(p);
/* GUIManager* gui = GetGraphics()->GetGUI();
GUIManager::me()->AddOverlay(AS_STRING("main_menu"));
GUIOverlay* mainMenu = GUIManager::me()->GetOverlay(AS_STRING("main_menu"));
//add button
GUIButton* button = new GUIButton(gui);
button->SetPosition(Vec2i(50,50));
button->SetWidth(200);
button->SetHeight(50);
button->SetBackColor(Vec4f(1.0f,0.0f,0.0f,0.99f));
mainMenu->AddChild(button);
//add button
GUIButton* button2 = new GUIButton(gui);
button2->SetPosition(Vec2i(50,110));
button2->SetWidth(200);
button2->SetHeight(50);
button2->SetBackColor(Vec4f(0.0f,1.0f,0.0f,0.99f));
mainMenu->AddChild(button2);
//add button
GUIButton* button3 = new GUIButton(gui);
button3->SetPosition(Vec2i(50,170));
button3->SetWidth(200);
button3->SetHeight(50);
button3->SetBackColor(Vec4f(0.0f,0.0f,1.0f,0.99f));
mainMenu->AddChild(button3);
button->Event_MouseEnter+=NewDelegate(this, &CrysisGame::BT1Entered);
button->Event_MouseLeave+=NewDelegate(this, &CrysisGame::BT1Leaved);
button->Event_MouseClick+=NewDelegate(this, &CrysisGame::BT1Click);
button->Event_MouseRightClick+=NewDelegate(this, &CrysisGame::BT1RightClick);
button->Event_MouseMiddleClick+=NewDelegate(this, &CrysisGame::BT1MiddleClick);
GUITextInput* ti = new GUITextInput(gui);
ti->SetPosition(Vec2i(320,50));
mainMenu->AddChild(ti);
GUITextInput* ti2 = new GUITextInput(gui);
ti2->SetPosition(Vec2i(320,100));
mainMenu->AddChild(ti2);
//add text
GUIText* text = new GUIText(gui);
mainMenu->AddChild(text);
text->SetPosition(Vec2i(50,5));
text->SetWidth(200);
text->SetText(STR("Ýòî êíîïêè! ÊÝÝÝÏ"));
text->SetBackColor(Vec4f(0.2f,0.2f,0.3f,0.9f));;
text->SetHAlign(HA_LEFT);
text->SetVAlign(VA_CENTER);
//add text
GUIText* text2 = new GUIText(gui);
mainMenu->AddChild(text2);
text2->SetPosition(Vec2i(320,5));
text2->SetWidth(200);
text2->SetText(STR("EditBox-û!"));
text2->SetBackColor(Vec4f(0.2f,0.2f,0.3f,0.9f));
text2->SetHAlign(HA_LEFT);
text2->SetVAlign(VA_CENTER);*/
}
void DoMainLoop()
{
bRunning = true;
while(bRunning)
{
//l = pGraphics->GetResourceManager()->CreatePointLight(Vec3f(-0.5f,0.4f,0), 3.0f);
/*l->intensity = cosf(GetGraphics()->appTime) * 0.5f + 1.2f;
l->getTransform()->SetPosition(Vec3f(sinf(GetGraphics()->appTime) * 0.5f, 0.4f, cosf(GetGraphics()->appTime) * 0.5f));
//l2 = pGraphics->GetResourceManager()->CreatePointLight(Vec3f(0.5f,0.4f,0), 3.0f);
l2->intensity = sinf(GetGraphics()->appTime + 0.25f) * 0.5f + 1.2f;
l2->getTransform()->SetPosition(Vec3f(0.5f, 0.4f, cosf(GetGraphics()->appTime) * 1.5f));
//l3 = pGraphics->GetResourceManager()->CreatePointLight(Vec3f(1.5f,0.4f,0), 3.0f);
l3->intensity = cosf(GetGraphics()->appTime + 0.75f) * 0.5f + 1.2f;
l3->getTransform()->SetPosition(Vec3f(1.5f, 0.4f, sinf(GetGraphics()->appTime) * 1.5f));*/
this->process();
}
}
};
#endif // MyGame_h__