librw/src/engine.cpp

208 lines
4.2 KiB
C++
Raw Normal View History

2016-06-16 14:08:09 +02:00
#include <cstdio>
#include <cstdlib>
#include <cassert>
2016-06-16 14:08:09 +02:00
#include "rwbase.h"
2017-08-09 10:57:32 +02:00
#include "rwerror.h"
2016-06-16 14:08:09 +02:00
#include "rwplg.h"
#include "rwpipeline.h"
#include "rwobjects.h"
#include "rwengine.h"
#include "ps2/rwps2.h"
#include "d3d/rwxbox.h"
#include "d3d/rwd3d.h"
#include "d3d/rwd3d8.h"
#include "d3d/rwd3d9.h"
#include "gl/rwgl3.h"
#include "gl/rwwdgl.h"
2016-06-16 14:08:09 +02:00
2017-08-09 10:57:32 +02:00
#define PLUGIN_ID 0
2016-06-16 14:08:09 +02:00
namespace rw {
Engine *engine;
2017-08-09 10:57:32 +02:00
PluginList Driver::s_plglist[NUM_PLATFORMS];
Engine::State Engine::state = Dead;
2017-08-09 10:57:32 +02:00
// This function mainly registers engine plugins
// RW initializes memory related things here too and
// uses more plugins
// TODO: do this^ ?
bool32
Engine::init(void)
{
2017-08-09 10:57:32 +02:00
if(engine || Engine::state != Dead){
RWERROR((ERR_ENGINEINIT));
return 0;
}
2017-08-09 10:57:32 +02:00
PluginList init = { sizeof(Driver), sizeof(Driver), nil, nil };
for(uint i = 0; i < NUM_PLATFORMS; i++)
2017-07-12 10:10:57 +02:00
Driver::s_plglist[i] = init;
2017-08-09 10:57:32 +02:00
// Register plugins
// TODO: these are wrong
ps2::initializePlatform();
xbox::initializePlatform();
d3d8::initializePlatform();
d3d9::initializePlatform();
wdgl::initializePlatform();
gl3::initializePlatform();
Engine::state = Initialized;
return 1;
}
// This is where RW allocates the engine and e.g. opens d3d
// TODO: this will take an argument with device specific data (HWND &c.)
bool32
Engine::open(void)
{
if(engine || Engine::state != Initialized){
RWERROR((ERR_ENGINEOPEN));
return 0;
}
2017-08-09 10:57:32 +02:00
// Allocate engine
engine = (Engine*)malloc(sizeof(Engine));
2016-07-21 08:59:06 +02:00
engine->currentCamera = nil;
engine->currentWorld = nil;
engine->currentTexDictionary = nil;
engine->imtexture = nil;
2016-08-05 01:13:41 +02:00
engine->loadTextures = 1;
engine->makeDummies = 1;
2016-07-21 08:59:06 +02:00
2017-08-09 10:57:32 +02:00
// Initialize device
// Device and possibly OS specific!
#ifdef RW_GL3
engine->device = gl3::renderdevice;
#elif RW_D3D9
engine->device = d3d::renderdevice;
#else
engine->device = null::renderdevice;
#endif
2016-07-06 11:44:59 +02:00
2017-08-09 10:57:32 +02:00
// TODO: open device; create d3d object/get video mode
2017-08-09 10:57:32 +02:00
// TODO: init driver functions
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
for(uint i = 0; i < NUM_PLATFORMS; i++){
2017-08-09 10:57:32 +02:00
rw::engine->driver[i] = (Driver*)malloc(Driver::s_plglist[i].size);
2017-08-09 10:57:32 +02:00
engine->driver[i]->defaultPipeline = defpipe;
2017-08-09 10:57:32 +02:00
engine->driver[i]->rasterCreate = null::rasterCreate;
engine->driver[i]->rasterLock = null::rasterLock;
engine->driver[i]->rasterUnlock = null::rasterUnlock;
engine->driver[i]->rasterNumLevels = null::rasterNumLevels;
engine->driver[i]->rasterFromImage = null::rasterFromImage;
engine->driver[i]->rasterToImage = null::rasterToImage;
}
2017-08-09 10:57:32 +02:00
Engine::state = Opened;
return 1;
}
2017-08-09 10:57:32 +02:00
// This is where RW creates the actual rendering device
// ans calls the engine plugin ctors
bool32
Engine::start(EngineStartParams *p)
{
if(engine == nil || Engine::state != Opened){
RWERROR((ERR_ENGINESTART));
return 0;
}
2017-08-09 10:57:32 +02:00
// Start device
engine->device.system(DEVICESTART, (void*)p);
engine->device.system(DEVICEINIT, nil);
// TODO: construct engine plugins
Frame::dirtyList.init();
for(uint i = 0; i < NUM_PLATFORMS; i++)
Driver::s_plglist[i].construct(rw::engine->driver[i]);
// TODO: finalize device start
Engine::state = Started;
return 1;
}
void
Engine::stop(void)
{
engine->device.system(DEVICESTOP, nil);
}
2016-06-16 14:08:09 +02:00
namespace null {
void beginUpdate(Camera*) { }
void endUpdate(Camera*) { }
2016-07-05 18:22:22 +02:00
void clearCamera(Camera*,RGBA*,uint32) { }
2017-08-09 10:57:32 +02:00
void showRaster(Raster*) { }
2016-07-05 11:36:43 +02:00
void setRenderState(int32, uint32) { }
uint32 getRenderState(int32) { return 0; }
void im2DRenderIndexedPrimitive(PrimitiveType, void*, int32, void*, int32) { }
2016-06-16 14:08:09 +02:00
void
rasterCreate(Raster*)
{
assert(0 && "rasterCreate not implemented");
}
uint8*
rasterLock(Raster*, int32)
{
assert(0 && "lockRaster not implemented");
return nil;
2016-06-16 14:08:09 +02:00
}
void
rasterUnlock(Raster*, int32)
{
assert(0 && "unlockRaster not implemented");
}
int32
2016-06-16 15:35:45 +02:00
rasterNumLevels(Raster*)
2016-06-16 14:08:09 +02:00
{
assert(0 && "rasterNumLevels not implemented");
return 0;
}
void
rasterFromImage(Raster*, Image*)
{
assert(0 && "rasterFromImage not implemented");
}
2016-07-15 11:55:52 +02:00
Image*
rasterToImage(Raster*)
{
assert(0 && "rasterToImage not implemented");
return nil;
}
2017-08-09 10:57:32 +02:00
int
devicesystem(DeviceReq req, void *arg0)
{
return 1;
}
Device renderdevice = {
0.0f, 1.0f,
null::beginUpdate,
null::endUpdate,
null::clearCamera,
null::showRaster,
null::setRenderState,
null::getRenderState,
null::im2DRenderIndexedPrimitive,
null::devicesystem
};
2016-06-16 14:08:09 +02:00
}
}