2017-08-09 23:42:33 +01:00
|
|
|
#include <rw.h>
|
|
|
|
#include "skeleton.h"
|
|
|
|
|
2020-04-16 22:09:47 +01:00
|
|
|
|
2017-08-09 23:42:33 +01:00
|
|
|
namespace sk {
|
|
|
|
|
|
|
|
Globals globals;
|
2017-08-23 11:21:23 +01:00
|
|
|
Args args;
|
2017-08-09 23:42:33 +01:00
|
|
|
|
2020-04-16 22:09:47 +01:00
|
|
|
|
2017-08-09 23:42:33 +01:00
|
|
|
bool
|
|
|
|
InitRW(void)
|
|
|
|
{
|
|
|
|
if(!rw::Engine::init())
|
|
|
|
return false;
|
|
|
|
if(AppEventHandler(sk::PLUGINATTACH, nil) == EVENTERROR)
|
|
|
|
return false;
|
2020-04-15 08:47:43 +01:00
|
|
|
if(!rw::Engine::open(&engineOpenParams))
|
2017-08-09 23:42:33 +01:00
|
|
|
return false;
|
2020-04-15 08:47:43 +01:00
|
|
|
|
|
|
|
SubSystemInfo info;
|
|
|
|
int i, n;
|
|
|
|
n = Engine::getNumSubSystems();
|
|
|
|
for(i = 0; i < n; i++)
|
|
|
|
if(Engine::getSubSystemInfo(&info, i))
|
|
|
|
printf("subsystem: %s\n", info.name);
|
2020-04-16 22:09:47 +01:00
|
|
|
Engine::setSubSystem(n-1);
|
2020-04-15 08:47:43 +01:00
|
|
|
|
|
|
|
int want = -1;
|
|
|
|
VideoMode mode;
|
|
|
|
n = Engine::getNumVideoModes();
|
|
|
|
for(i = 0; i < n; i++)
|
|
|
|
if(Engine::getVideoModeInfo(&mode, i)){
|
2020-04-16 22:09:47 +01:00
|
|
|
// if(mode.width == 640 && mode.height == 480 && mode.depth == 32)
|
|
|
|
if(mode.width == 1920 && mode.height == 1080 && mode.depth == 32)
|
2020-04-15 08:47:43 +01:00
|
|
|
want = i;
|
|
|
|
printf("mode: %dx%dx%d %d\n", mode.width, mode.height, mode.depth, mode.flags);
|
|
|
|
}
|
|
|
|
// if(want >= 0) Engine::setVideoMode(want);
|
|
|
|
Engine::getVideoModeInfo(&mode, Engine::getCurrentVideoMode());
|
|
|
|
|
|
|
|
if(mode.flags & VIDEOMODEEXCLUSIVE){
|
|
|
|
globals.width = mode.width;
|
|
|
|
globals.height = mode.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!rw::Engine::start())
|
2017-08-09 23:42:33 +01:00
|
|
|
return false;
|
|
|
|
|
2021-03-03 15:43:20 +00:00
|
|
|
rw::Charset::open();
|
|
|
|
|
2017-08-27 16:13:10 +01:00
|
|
|
rw::Image::setSearchPath("./");
|
2017-08-09 23:42:33 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TerminateRW(void)
|
|
|
|
{
|
2021-03-03 15:43:20 +00:00
|
|
|
rw::Charset::close();
|
|
|
|
|
2017-08-09 23:42:33 +01:00
|
|
|
// TODO: delete all tex dicts
|
|
|
|
rw::Engine::stop();
|
|
|
|
rw::Engine::close();
|
|
|
|
rw::Engine::term();
|
|
|
|
}
|
|
|
|
|
2017-10-21 21:21:36 +01:00
|
|
|
Camera*
|
|
|
|
CameraCreate(int32 width, int32 height, bool32 z)
|
|
|
|
{
|
|
|
|
Camera *cam;
|
|
|
|
cam = Camera::create();
|
|
|
|
cam->setFrame(Frame::create());
|
|
|
|
cam->frameBuffer = Raster::create(width, height, 0, Raster::CAMERA);
|
|
|
|
cam->zBuffer = Raster::create(width, height, 0, Raster::ZBUFFER);
|
|
|
|
return cam;
|
|
|
|
}
|
|
|
|
|
2021-03-03 01:15:38 +00:00
|
|
|
void
|
|
|
|
CameraDestroy(rw::Camera *cam)
|
|
|
|
{
|
|
|
|
if(cam->frameBuffer){
|
|
|
|
cam->frameBuffer->destroy();
|
|
|
|
cam->frameBuffer = nil;
|
|
|
|
}
|
|
|
|
if(cam->zBuffer){
|
|
|
|
cam->zBuffer->destroy();
|
|
|
|
cam->zBuffer = nil;
|
|
|
|
}
|
|
|
|
rw::Frame *frame = cam->getFrame();
|
|
|
|
if(frame){
|
|
|
|
cam->setFrame(nil);
|
|
|
|
frame->destroy();
|
|
|
|
}
|
|
|
|
cam->destroy();
|
|
|
|
}
|
|
|
|
|
2017-10-20 21:38:28 +01:00
|
|
|
void
|
2021-03-03 20:53:06 +00:00
|
|
|
CameraSize(Camera *cam, Rect *r, float viewWindow, float aspectRatio)
|
2017-10-20 21:38:28 +01:00
|
|
|
{
|
|
|
|
if(cam->frameBuffer){
|
|
|
|
cam->frameBuffer->destroy();
|
|
|
|
cam->frameBuffer = nil;
|
|
|
|
}
|
|
|
|
if(cam->zBuffer){
|
|
|
|
cam->zBuffer->destroy();
|
|
|
|
cam->zBuffer = nil;
|
|
|
|
}
|
|
|
|
cam->frameBuffer = Raster::create(r->w, r->h, 0, Raster::CAMERA);
|
|
|
|
cam->zBuffer = Raster::create(r->w, r->h, 0, Raster::ZBUFFER);
|
2021-03-03 20:53:06 +00:00
|
|
|
|
|
|
|
if(viewWindow != 0.0f){
|
|
|
|
rw::V2d vw;
|
|
|
|
// TODO: aspect ratio when fullscreen
|
|
|
|
if(r->w > r->h){
|
|
|
|
vw.x = viewWindow;
|
|
|
|
vw.y = viewWindow / ((float)r->w/r->h);
|
|
|
|
}else{
|
|
|
|
vw.x = viewWindow / ((float)r->h/r->w);
|
|
|
|
vw.y = viewWindow;
|
|
|
|
}
|
|
|
|
cam->setViewWindow(&vw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CameraMove(Camera *cam, V3d *delta)
|
|
|
|
{
|
|
|
|
rw::V3d offset;
|
|
|
|
rw::V3d::transformVectors(&offset, delta, 1, &cam->getFrame()->matrix);
|
|
|
|
cam->getFrame()->translate(&offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CameraPan(Camera *cam, V3d *pos, float angle)
|
|
|
|
{
|
|
|
|
rw::Frame *frame = cam->getFrame();
|
|
|
|
rw::V3d trans = pos ? *pos : frame->matrix.pos;
|
|
|
|
rw::V3d negTrans = rw::scale(trans, -1.0f);
|
|
|
|
frame->translate(&negTrans);
|
|
|
|
frame->rotate(&frame->matrix.up, angle);
|
|
|
|
frame->translate(&trans);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CameraTilt(Camera *cam, V3d *pos, float angle)
|
|
|
|
{
|
|
|
|
rw::Frame *frame = cam->getFrame();
|
|
|
|
rw::V3d trans = pos ? *pos : frame->matrix.pos;
|
|
|
|
rw::V3d negTrans = rw::scale(trans, -1.0f);
|
|
|
|
frame->translate(&negTrans);
|
|
|
|
frame->rotate(&frame->matrix.right, angle);
|
|
|
|
frame->translate(&trans);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CameraRotate(Camera *cam, V3d *pos, float angle)
|
|
|
|
{
|
|
|
|
rw::Frame *frame = cam->getFrame();
|
|
|
|
rw::V3d trans = pos ? *pos : frame->matrix.pos;
|
|
|
|
rw::V3d negTrans = rw::scale(trans, -1.0f);
|
|
|
|
frame->translate(&negTrans);
|
|
|
|
frame->rotate(&frame->matrix.at, angle);
|
|
|
|
frame->translate(&negTrans);
|
2017-10-20 21:38:28 +01:00
|
|
|
}
|
|
|
|
|
2017-08-09 23:42:33 +01:00
|
|
|
EventStatus
|
|
|
|
EventHandler(Event e, void *param)
|
|
|
|
{
|
|
|
|
EventStatus s;
|
|
|
|
s = AppEventHandler(e, param);
|
|
|
|
if(e == QUIT){
|
|
|
|
globals.quit = 1;
|
|
|
|
return EVENTPROCESSED;
|
|
|
|
}
|
|
|
|
if(s == EVENTNOTPROCESSED)
|
|
|
|
switch(e){
|
|
|
|
case RWINITIALIZE:
|
|
|
|
return InitRW() ? EVENTPROCESSED : EVENTERROR;
|
|
|
|
case RWTERMINATE:
|
|
|
|
TerminateRW();
|
|
|
|
return EVENTPROCESSED;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|