My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* GPUEntsControl.cpp
*
* Created on: Oct 4, 2008
* Author: bey0nd
*/
#include <stdexcept>
#include <cstdlib>
using namespace std;
#include "GPUEntsControl.h"
#include "GPUEntities.h"
#include "LifeCycleDelegates.h"
#include "EventDelegates.h"
#include "PingPongShaders.h"

namespace ZGame
{

GPUEntsControl::GPUEntsControl() :
_elapsedT(0.0f), _gpuEnts(0)
{
// TODO Auto-generated constructor stub

}

GPUEntsControl::~GPUEntsControl()
{
// TODO Auto-generated destructor stub
}

void
GPUEntsControl::attachGPUEnts(GPUEntities* ents)
{

if (!ents)
throw std::invalid_argument(
"Attempting to attach a null GPUEntities in GPUEntsControl.");

_gpuEnts = ents;
init();
}

void
GPUEntsControl::init()
{
LogManager* lm = LogManager::getSingletonPtr();
lm->logMessage(LML_TRIVIAL, "In GPUEntsControl::init");
_stateTex = TextureManager::getSingleton().getByName(
_gpuEnts->getEntsData());
assert(!_stateTex.isNull() && "_stateTex is null in GPUEntsControl::init()");
_dirTex = TextureManager::getSingleton().getByName(
_gpuEnts->getGpuEntsDirData());
assert(!_stateTex.isNull() && "_dirTex is null in GPUEntsControl::init()");
//Setup the ping pongs
_posPingPong.reset(new PingPongShaders(_stateTex, MaterialPtr(
MaterialManager::getSingleton().getByName(
"ZGame/GPUEntsPosUpdatePingPong")), Real(50000.0f)));
_dirPingPong.reset(new PingPongShaders(_dirTex, MaterialPtr(
MaterialManager::getSingleton().getByName(
"ZGame/GPUEntsDirUpdatePingPong")), Real(50000.0f)));
//attach direction texture to pos update shader
MaterialPtr posMat = MaterialManager::getSingleton().getByName(
"ZGame/GPUEntsPosUpdatePingPong");
assert(!posMat.isNull() && "posMat in null GPUEntsControl::init");
posMat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
_dirTex->getName());

lm->logMessage(LML_TRIVIAL, "Out GPUEntsControl::init");
}

void
GPUEntsControl::fillLfcObservers(LifeCycle::LifeCycleObserver &obs)
{
obs.onUpdate.bind(&GPUEntsControl::onUpdate, this);
}

bool
GPUEntsControl::onInit()
{
return true;
}

bool
GPUEntsControl::onUpdate(const Ogre::FrameEvent &evt)
{
srand(_timer.getMillisecondsCPU());
int randNum = rand();
MaterialPtr mat = MaterialManager::getSingleton().getByName(
"ZGame/GPUEntsDirUpdatePingPong");
Ogre::GpuProgramParametersSharedPtr gpu =
mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
//update direction
gpu->setNamedConstant("key", randNum);
_dirPingPong->pingPong();
gpu->setNamedConstant("dt", evt.timeSinceLastFrame);
//update position
mat = MaterialManager::getSingleton().getByName(
"ZGame/GPUEntsPosUpdatePingPong");
mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant(
"dt", evt.timeSinceLastFrame);
_posPingPong->pingPong();
return true;
}

}
Show details Hide details

Change log

r50 by llwijk on Oct 10, 2008   Diff
More updates to GPU zombie controller.
Go to: 
Project members, sign in to write a code review

Older revisions

r49 by llwijk on Oct 09, 2008   Diff
It's ALIVE! Finished the very first
version of Zombie wandering. They
move!
r47 by llwijk on Oct 07, 2008   Diff
Added observer injection support to
the game state, so to have easier
registering for events. The idea is in
any gamestate, we simply invoke
add(whateverObs), and add this to an
...
r44 by llwijk on Oct 05, 2008   Diff
White Noise generator implemented.
All revisions of this file

File info

Size: 3060 bytes, 105 lines
Hosted by Google Code