int Application::Run() {
Setup();
if (!engine_->Initialize(engineParameters_)) {
return ErrorExit();
}
Start();
#if !defined(IOS) && !defined(__EMSCRIPTEN__)
while (!engine_->IsExiting())
engine_->RunFrame();
Stop();
#else
#if defined(IOS)
SDL_iPhoneSetAnimationCallback(GetWindow(), 1, &RunFrame, engine_);
#elif defined(__EMSCRIPTEN__)
emscripten_set_main_loop_arg(RunFrame, engine_, 0, 1);
#endif
#endif
return exitCode_;
}
void Engine::RunFrame() {
Time* time = GetSubsystem<Time>();
Input* input = GetSubsystem<Input>();
Audio* audio = GetSubsystem<Audio>();
time->BeginFrame(timeStep_);
// ... process input and audio
Update();
fpsTimeSinceUpdate_ += timeStep_;
++fpsFramesSinceUpdate_;
if (fpsTimeSinceUpdate_ > ENGINE_FPS_UPDATE_INTERVAL) {
fps_ = (int)(fpsFramesSinceUpdate_ / fpsTimeSinceUpdate_);
fpsFramesSinceUpdate_ = 0;
fpsTimeSinceUpdate_ = 0;
}
Render();
ApplyFrameLimit();
time->EndFrame();
}
void Engine::Update() {
VariantMap& eventData = GetEventDataMap();
eventData[P_TIMESTEP] = timeStep_;
SendEvent(E_UPDATE, eventData);
// Logic post-update event
SendEvent(E_POSTUPDATE, eventData);
// Rendering update event
SendEvent(E_RENDERUPDATE, eventData);
// Post-render update event
SendEvent(E_POSTRENDERUPDATE, eventData);
}
void Engine::Render() {
// If device is lost, BeginFrame will fail and we skip rendering
Graphics* graphics = GetSubsystem<Graphics>();
if (!graphics->BeginFrame()) return;
GetSubsystem<Renderer>()->Render();
GetSubsystem<UI>()->Render();
graphics->EndFrame();
}
Object 2 reads updated state of Object 1 but not updated state of Object 3
It's difficult to persuade people to spend time and money on high-quality sound in games. At the same time, most users would better get a new 3D accelerator than a new sound card.
Detects input events from devices
// Returns 1 if the cheat was successful, 0 if failed.
int cht_CheckCheat(cheatseq_t* cht, char key ) {
int i;
int rc = 0;
if (firsttime) {
firsttime = 0;
for (i=0;i<256;i++) cheat_xlate_table[i] = SCRAMBLE(i);
}
// initialize if first time
if (!cht->p) cht->p = cht->sequence;
if (*cht->p == 0) *(cht->p++) = key;
else if (cheat_xlate_table[(unsigned char)key] == *cht->p) cht->p++;
else cht->p = cht->sequence;
if (*cht->p == 1) cht->p++;
else if (*cht->p == 0xff) { // end of sequence character
cht->p = cht->sequence;
rc = 1;
}
return rc;
}
void* AllocatorReserve(AllocatorBlock* allocator) {
if (!allocator->free_) {
// Free nodes have been exhausted. Allocate a new larger block
unsigned newCapacity = (allocator->capacity_ + 1) >> 1;
AllocatorReserveBlock(allocator, allocator->nodeSize_, newCapacity);
allocator->capacity_ += newCapacity;
}
// We should have new free node(s) chained
AllocatorNode* freeNode = allocator->free_;
void* ptr = (reinterpret_cast<unsigned char*>(freeNode)) + sizeof(AllocatorNode);
allocator->free_ = freeNode->next_;
freeNode->next_ = 0;
return ptr;
}
============================
// create node from void* and call the constructor
Node* newNode = static_cast<Node*>(AllocatorReserve(allocator_));
new(newNode) Node();
// ... do some stuff
// delete node
(newNode)->~Node();
AllocatorFree(allocator_, newNode);
Tomb Raider (2015)
Doom 4 (2016)
Raptor (1994)
Portal (2007)
Duke Nukem (1991)
Arma III (2012)
Comanche (1992)
Technology is incredible