kskels/bomba — Issue #10: Add base main.cpp
Author: peteb
Created: 2011-11-25 12:23:26+00:00
State: open

Commit a baseline main.cpp containing calls to stub classes and functions. Like this:

```c++
// some objects are locally simulated, others are dummies
// dummies should be provided with delta packets
class Missile : Entity {
public:
void onInput(PlayerInput) {

}

void update(double) {
if (Entity::isRemote) {
extrapolate();
}
else {
boo();
}
}

void render(double) {

}

NetMsg *state(NetMsg &) {
// current state for sending to server
}
};

GfxDevice *createGfxDevice();
SndDevice *createSndDevice();
HiDevice *createHiDevice();
Entity *createEntity(EntityFullState &);
void drawMessage(GfxDevice *, const char *);

int main() {
int localPlayer = 0; // should be set when information is received from server

map entities;
TileMap tiles;
bool running = true;
Connection client;
GfxDevice *gfx = createGfxDevice();
SndDevice *snd = createSndDevice();
HiDevice *hid = createHiDevice();
ParticleSystem particles;
GuiScreen *lobby = createLobby();

while (running) {
vector msgs = client.readNet();
msgs.each {
case info: PlayerInfo:
localPlayer = info.player_id;

case msg: InputUpdate:
entities[msg.id]->inInput(msg.input);

case entity: EntityFullState:
entities[msg.id] = createEntity(entity, tiles);
particles.spawnEffect(ENTITY_SPAWNED, msg.coord);
sndDevice->playSound("entity_spawned", msg.coord);

case msg: EntityStateChange:
delete entities[msg.id];
entities.erase(msg.id);
// effects...?

case map: MapUpdate:
tiles.assign(map);
}

if (client.state() == CONNECTED) {
if (PlayerInput in = hid->readInput()) {
if (in.escapePressed)
running = false;

entities[localPlayer]->onInput(in);
NetMsg inputUpdate;
if (entities[localPlayer]->state(inputUpdate))
client.send(inputUpdate);
}

entities.each {_.update(currentTime)} // update entities according to time and input
map.render(gfx, currentTime);
entities.each {_.render(gfx, currentTime)} // render graphics according to entity state and time
drawOverlay(gfx);
}
else if (client.state() == CONNECTING) {
drawMessage(gfx, "Connecting...");
static double connectTime = 0.0;
connectTime += dt;
if (connectTime > 10.0) {
client.shutdown();
connectTime = 0.0;
}
}
else {
lobby->update(currentTime, hid);
lobby->draw(currentTime);
if (lobby->state().key == GuiScreen::STATE_CONNECT) { // this could be reversed, dip.
client.connect(lobby->state().value);
lobby->resetState();
}
}

gfx->flip();
}

}
```