@@ -28,7 +28,9 @@ Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/process.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/clipboard.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/textedit.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/sprites.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/sprite_animation.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/sprite_physics.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/joint2D.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/tilemaps.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/mesh.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/actor.bas"
|
||||
@@ -40,5 +42,5 @@ Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/particles.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/lights.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/terrain.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/water.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/animation.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/actor_animation.bas"
|
||||
Include "/home/n00b/Projects/RCBASIC4/rcbasic_build/intern_lib/materials.bas"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
function CreateMeshActor( mesh )
|
||||
function CreateMeshOctreeActor( mesh )
|
||||
function CreateAnimatedActor( mesh )
|
||||
function CreateOctreeActor( mesh )
|
||||
function CreateCubeActor( cube_size )
|
||||
function CreateSphereActor( radius )
|
||||
function CreateWaterPlaneActor( w, h )
|
||||
function CreateWaterActor( mesh, waveHeight, waveSpeed, waveLength )
|
||||
function CreateLightActor( )
|
||||
function CreateBillboardActor( )
|
||||
function CreateTerrainActor( hmap_file$ )
|
||||
|
||||
15
rcbasic_build/intern_lib/actor_animation.bas
Normal file
15
rcbasic_build/intern_lib/actor_animation.bas
Normal file
@@ -0,0 +1,15 @@
|
||||
Function CreateActorAnimation(actor, start_frame, end_frame, speed)
|
||||
sub SetActorAnimation( actor, animation, num_loops)
|
||||
sub SetActorAnimationSpeed( actor, animation, speed )
|
||||
sub SetActorAnimationFrames(actor, animation, start_frame, end_frame)
|
||||
Function GetActorCurrentAnimation(actor)
|
||||
function GetActorAnimationSpeed( actor, animation )
|
||||
Function GetActorAnimationStartFrame(actor, animation)
|
||||
Function GetActorAnimationEndFrame(actor, animation)
|
||||
sub SetActorFrame(actor, frame)
|
||||
function GetActorFrame(actor)
|
||||
function ActorAnimationIsPlaying(actor)
|
||||
function NumActorAnimationLoops(actor)
|
||||
sub SetActorMD2Animation( actor, anim, num_loops )
|
||||
sub SetActorMD2AnimationByName( actor, anim_name$, num_loops )
|
||||
sub DeleteActorAnimation(actor, animation)
|
||||
@@ -12,3 +12,6 @@ sub SetCameraFarValue( zf )
|
||||
function GetCameraFarValue( )
|
||||
sub SetCameraNearValue( zn )
|
||||
function GetCameraNearValue( )
|
||||
Sub SetProjectionMatrix(matA, projection_type)
|
||||
Sub GetProjectionMatrix(matA )
|
||||
Sub GetWorldToViewportPosition(x, y, z, ByRef vx, ByRef vy)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function OpenCanvas( w, h, viewport_x, viewport_y, viewport_w, viewport_h, mode)
|
||||
Sub CloseCanvas(c_num)
|
||||
function OpenCanvas3D( w, h, viewport_x, viewport_y, viewport_w, viewport_h, mode)
|
||||
function OpenCanvas3D( viewport_x, viewport_y, viewport_w, viewport_h, mode)
|
||||
sub SetCanvasVisible(c_num, flag)
|
||||
function CanvasIsVisible(c_num)
|
||||
sub SetCanvasViewport(cnum, x, y, w, h)
|
||||
@@ -16,8 +16,8 @@ sub SetCanvasColorMod(c_num, c)
|
||||
function GetCanvasColorMod(c_num)
|
||||
function CloneCanvas(c_num, mode)
|
||||
sub SetCanvasZ(c_num, z)
|
||||
function GetCanvasZ(c_num)
|
||||
function CanvasZ(c_num)
|
||||
function CanvasClip(x, y, w, h)
|
||||
function ActiveCanvas()
|
||||
sub SetCanvasPhysics2D(c_num, state)
|
||||
function OpenSpriteCanvas(w, h, viewport_x, viewport_y, viewport_w, viewport_h)
|
||||
function OpenCanvasSpriteLayer(w, h, viewport_x, viewport_y, viewport_w, viewport_h)
|
||||
|
||||
0
rcbasic_build/intern_lib/joint2D.bas
Normal file
0
rcbasic_build/intern_lib/joint2D.bas
Normal file
@@ -3,3 +3,8 @@ sub DeleteMesh( mesh )
|
||||
function CreateMesh( )
|
||||
sub AddMeshBuffer( mesh, vertex_count, ByRef vertex_data, ByRef normal_data, ByRef uv_data, index_count, ByRef index_data )
|
||||
function LoadMeshFromArchive( archive$, mesh_file$ )
|
||||
Function CreatePlaneMesh( w, h, tileCount_w, tileCount_h )
|
||||
Function LoadAN8( an8_file$ )
|
||||
Function LoadMeshFromAN8(an8_project, an8_scene$)
|
||||
Function GetNumAN8Scenes(an8_project)
|
||||
Function GetAN8SceneName$(an8_project, scene_num)
|
||||
|
||||
15
rcbasic_build/intern_lib/sprite_animation.bas
Normal file
15
rcbasic_build/intern_lib/sprite_animation.bas
Normal file
@@ -0,0 +1,15 @@
|
||||
Function CreateSpriteAnimation(sprite, anim_length, speed)
|
||||
Sub SetSpriteFrame(sprite, frame)
|
||||
Function GetSpriteFrame(sprite)
|
||||
Sub SetSpriteAnimationFrame(sprite, animation, anim_frame, frame)
|
||||
Function GetSpriteAnimationFrame(sprite, animation, anim_frame)
|
||||
Sub SetSpriteAnimationLength(sprite, animation, anim_length)
|
||||
Function GetSpriteAnimationLength(sprite, animation)
|
||||
Sub SetSpriteAnimationSpeed(sprite, animation, speed)
|
||||
Function GetSpriteAnimationSpeed(sprite, animation)
|
||||
Sub SetSpriteAnimation(sprite, animation, num_loops)
|
||||
Function GetSpriteAnimation(sprite)
|
||||
Function GetSpriteCurrentAnimationFrame(sprite)
|
||||
Function NumSpriteAnimationLoops(sprite)
|
||||
Function SpriteAnimationIsPlaying(sprite)
|
||||
Sub DeleteSpriteAnimation(sprite, animation)
|
||||
@@ -1,3 +1,26 @@
|
||||
function CreateSprite( img )
|
||||
function CreateSprite( img, frame_w, frame_h )
|
||||
Sub DeleteSprite( sprite )
|
||||
Sub SetSpritePosition( sprite, x, y )
|
||||
Sub TranslateSprite(sprite, x, y)
|
||||
Sub GetSpritePosition(sprite, ByRef x, ByRef y)
|
||||
Function SpriteX(sprite)
|
||||
Function SpriteY(sprite)
|
||||
Sub SetSpriteRotation(sprite, angle)
|
||||
Sub RotateSprite(sprite, angle)
|
||||
Function GetSpriteRotation(sprite)
|
||||
Sub SetSpriteScale(sprite, x, y)
|
||||
Sub ScaleSprite(sprite, x, y)
|
||||
Sub GetSpriteScale(sprite, ByRef x, ByRef y)
|
||||
Sub SetSpriteZ(sprite, z)
|
||||
Function SpriteZ(sprite)
|
||||
Sub GetSpriteSize(sprite, ByRef w, ByRef h)
|
||||
Function SpriteWidth(sprite)
|
||||
Function SpriteHeight(sprite)
|
||||
Sub SetSpriteVisible(sprite, flag)
|
||||
Function SpriteIsVisible(sprite)
|
||||
Sub SetSpriteSolid(sprite, flag)
|
||||
Function SpriteIsSolid(sprite)
|
||||
Sub SetSpriteType(sprite, sprite_type)
|
||||
Function GetSpriteType(sprite)
|
||||
Sub SetSpriteSource(sprite, img)
|
||||
Function GetSpriteSource(sprite)
|
||||
|
||||
@@ -4,5 +4,5 @@ Function FontExists(slot)
|
||||
sub SetFont(slot)
|
||||
sub DrawText(txt$, x, y)
|
||||
sub GetTextSize(txt$, byref w, byref h)
|
||||
function GetTextWidth(txt$)
|
||||
function GetTextHeight(txt$)
|
||||
function TextWidth(txt$)
|
||||
function TextHeight(txt$)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
sub setWaterWindForce( actor, f)
|
||||
function getWaterWindForce( actor)
|
||||
sub setWaterWaveHeight( actor, h)
|
||||
function getWaterWaveHeight( actor)
|
||||
sub setWaterWindDirection( actor, x, z)
|
||||
sub getWaterWindDirection( actor, ByRef x, ByRef z)
|
||||
sub setWaterColor( actor, c)
|
||||
function getWaterColor( actor)
|
||||
sub setWaterColorBlendFactor( actor, cbfactor)
|
||||
function getWaterColorBlendFactor( actor)
|
||||
|
||||
@@ -45,6 +45,6 @@ sub RestoreWindow( )
|
||||
sub GrabInput(flag)
|
||||
sub SetWindowAlwaysOnTop( flag )
|
||||
sub SetMouseRelative(flag)
|
||||
sub SetWindowVSync( flag )
|
||||
function FlashWindow( flag )
|
||||
function WindowIsGrabbed( )
|
||||
Sub PreUpdate( )
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@
|
||||
#include <box2d/box2d.h>
|
||||
#include "rc_sprite2D.h"
|
||||
#include "rc_spritelib.h"
|
||||
#include "rc_tilelib.h"
|
||||
#include <irrtheora.h>
|
||||
|
||||
using namespace irr;
|
||||
@@ -1019,9 +1020,10 @@ int rc_canvasOpen3D(int vx, int vy, int vw, int vh, int mode)
|
||||
return rc_canvasOpen(vw, vh, vx, vy, vw, vh, mode, RC_CANVAS_TYPE_3D);
|
||||
}
|
||||
|
||||
int rc_canvasOpenSpriteLayer(int w, int h, int vx, int vy, int vw, int vh)
|
||||
int rc_canvasOpenSpriteLayer(int vx, int vy, int vw, int vh)
|
||||
{
|
||||
return rc_canvasOpen(w, h, vx, vy, vw, vh, 1, RC_CANVAS_TYPE_SPRITE);
|
||||
//sprite layers are basically infinite since you are just placing objects in the world
|
||||
return rc_canvasOpen(vw, vh, vx, vy, vw, vh, 1, RC_CANVAS_TYPE_SPRITE);
|
||||
}
|
||||
|
||||
void rc_setCanvasPhysics2D(int canvas_id, bool flag)
|
||||
@@ -3458,7 +3460,11 @@ bool rc_update()
|
||||
//std::cout << "draw canvas[" << canvas_id << "]" << std::endl;
|
||||
|
||||
if(rc_canvas[canvas_id].type == RC_CANVAS_TYPE_SPRITE)
|
||||
{
|
||||
|
||||
src = irr::core::rect<s32>( irr::core::vector2d<s32>(0, 0), rc_canvas[canvas_id].viewport.dimension); //sprite layers will just offset the sprites in drawSprites()
|
||||
drawSprites(canvas_id);
|
||||
}
|
||||
|
||||
draw2DImage2(VideoDriver, rc_canvas[canvas_id].texture, src, dest, irr::core::position2d<irr::s32>(0, 0), 0, true, color, screenSize);
|
||||
|
||||
|
||||
@@ -795,7 +795,8 @@ void drawSprites(int canvas_id)
|
||||
rc_canvas[canvas_id].physics2D.world->Step(step, velocityIterations, positionIterations);
|
||||
|
||||
//Setting the render target to the current canvas. NOTE: I might change this target to a separate sprite layer later.
|
||||
VideoDriver->setRenderTarget(rc_canvas[canvas_id].texture, true, false);
|
||||
VideoDriver->setRenderTarget(rc_canvas[canvas_id].texture, true, true);
|
||||
VideoDriver->clearBuffers(true, true, true, irr::video::SColor(0,0,0,0));
|
||||
|
||||
|
||||
irr::core::dimension2d<irr::u32> src_size;
|
||||
@@ -823,12 +824,38 @@ void drawSprites(int canvas_id)
|
||||
|
||||
double spr_timer = SDL_GetTicks();
|
||||
|
||||
int offset_x = rc_canvas[canvas_id].offset.X;
|
||||
int offset_y = rc_canvas[canvas_id].offset.Y;
|
||||
|
||||
for(int spr_index = 0; spr_index < rc_canvas[canvas_id].sprite.size(); spr_index++)
|
||||
{
|
||||
rc_sprite2D_obj* sprite = rc_canvas[canvas_id].sprite[spr_index];
|
||||
if(!sprite->visible)
|
||||
continue;
|
||||
|
||||
physics_pos = sprite->physics.body->GetPosition();
|
||||
x = (int)physics_pos.x - offset_x;
|
||||
y = (int)physics_pos.y - offset_y;
|
||||
|
||||
int xf = x + sprite->frame_size.Width;
|
||||
int yf = y + sprite->frame_size.Height;
|
||||
|
||||
//std::cout << "sprite info: " << xf << ", " << x << ", " << rc_canvas[canvas_id].viewport.dimension.Width << std::endl;
|
||||
|
||||
if( (xf < 0) || (x > ((int)rc_canvas[canvas_id].viewport.dimension.Width)) )
|
||||
{
|
||||
//std::cout << "skip draw[X]: " << spr_index << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( (yf < 0) || (y > ((int)rc_canvas[canvas_id].viewport.dimension.Height)) )
|
||||
{
|
||||
//std::cout << "skip draw[Y]: " << spr_index << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
position.set(x, y);
|
||||
|
||||
int img_id = sprite->image_id;
|
||||
if(img_id < 0 || img_id >= rc_image.size())
|
||||
continue;
|
||||
@@ -869,10 +896,10 @@ void drawSprites(int canvas_id)
|
||||
sourceRect = irr::core::rect<irr::s32>( frame_pos, src_size);
|
||||
//sourceRect = irr::core::rect<irr::s32>( irr::core::vector2d<irr::s32>(0, 0), src_size);
|
||||
|
||||
physics_pos = sprite->physics.body->GetPosition();
|
||||
x = (int)physics_pos.x;
|
||||
y = (int)physics_pos.y;
|
||||
position.set(x, y);
|
||||
//physics_pos = sprite->physics.body->GetPosition();
|
||||
//x = (int)physics_pos.x;
|
||||
//y = (int)physics_pos.y;
|
||||
//position.set(x, y);
|
||||
|
||||
|
||||
rotationPoint.set(x + (src_size.Width/2), y + (src_size.Height/2)); //TODO: need to account for offset once that is implemented
|
||||
|
||||
@@ -370,7 +370,7 @@ inline std::string rc_intern_replace(std::string src, std::string tgt, std::stri
|
||||
return src;
|
||||
}
|
||||
|
||||
inline string rc_intern_reverse(std::string rpc_string)
|
||||
inline std::string rc_intern_reverse(std::string rpc_string)
|
||||
{
|
||||
std::string n_str = "";
|
||||
if(rpc_string.length()==0)
|
||||
@@ -409,7 +409,7 @@ inline std::string rc_intern_rtrim(std::string src)
|
||||
if(i < 0)
|
||||
return "";
|
||||
|
||||
if(src.find_first_not_of(" ") == string::npos)
|
||||
if(src.find_first_not_of(" ") == std::string::npos)
|
||||
return "";
|
||||
|
||||
return utf8_substr(src,0,i+1);
|
||||
@@ -436,7 +436,7 @@ inline std::string rc_intern_stringFromBuffer(double* buffer, size_t buffer_size
|
||||
return (std::string)c_buf;
|
||||
}
|
||||
|
||||
inline string rc_intern_stringfill(std::string f_string, size_t n)
|
||||
inline std::string rc_intern_stringfill(std::string f_string, size_t n)
|
||||
{
|
||||
std::string f = "";
|
||||
for(size_t i = 0; i < n; i++)
|
||||
@@ -446,21 +446,21 @@ inline string rc_intern_stringfill(std::string f_string, size_t n)
|
||||
|
||||
inline std::string rc_intern_str(double n)
|
||||
{
|
||||
stringstream ss;
|
||||
std::stringstream ss;
|
||||
ss << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline std::string rc_intern_str_f(double n)
|
||||
{
|
||||
stringstream ss;
|
||||
std::stringstream ss;
|
||||
ss << fixed << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline std::string rc_intern_str_s(double n)
|
||||
{
|
||||
stringstream ss;
|
||||
std::stringstream ss;
|
||||
ss << scientific << n;
|
||||
return ss.str();
|
||||
}
|
||||
@@ -608,7 +608,7 @@ inline double rc_intern_frac(double n)
|
||||
|
||||
inline std::string rc_intern_hex(uint64_t n)
|
||||
{
|
||||
stringstream ss;
|
||||
std::stringstream ss;
|
||||
ss << hex << n;
|
||||
return ss.str();
|
||||
}
|
||||
@@ -616,7 +616,7 @@ inline std::string rc_intern_hex(uint64_t n)
|
||||
inline double rc_intern_hexInt(std::string n)
|
||||
{
|
||||
uint64_t x;
|
||||
stringstream ss;
|
||||
std::stringstream ss;
|
||||
ss << hex << n;
|
||||
ss >> x;
|
||||
return (double)x;
|
||||
|
||||
413
rcbasic_runtime/rc_tilelib.h
Normal file
413
rcbasic_runtime/rc_tilelib.h
Normal file
@@ -0,0 +1,413 @@
|
||||
#ifndef RC_TILELIB_H_INCLUDED
|
||||
#define RC_TILELIB_H_INCLUDED
|
||||
|
||||
#ifdef RC_ANDROID
|
||||
#include "SDL.h"
|
||||
#else
|
||||
#include <SDL2/SDL.h>
|
||||
#endif // _IRR_ANDROID_PLATFORM_
|
||||
|
||||
#include "rc_tilemap.h"
|
||||
#include "rc_gfx_core.h"
|
||||
|
||||
|
||||
int rc_createTileSet(int img_id, int tile_w, int tile_h)
|
||||
{
|
||||
if(img_id < 0 || img_id >= rc_image.size())
|
||||
return -1;
|
||||
|
||||
if(!rc_image[img_id].image)
|
||||
return -1;
|
||||
|
||||
rc_tileset_obj tset;
|
||||
|
||||
tset.active = true;
|
||||
tset.img_id = img_id;
|
||||
|
||||
tset.tile_width = tile_w;
|
||||
tset.tile_height = tile_h;
|
||||
|
||||
int num_tiles = ((int)rc_image[img_id].image->getSize().Width / tile_w) * ((int)rc_image[img_id].image->getSize().Height / tile_h);
|
||||
tset.tiles.resize(num_tiles);
|
||||
|
||||
for(int i = 0; i < tset.tiles.size(); i++)
|
||||
{
|
||||
tset.tiles[i].frames.push_back(i);
|
||||
tset.tiles[i].fps = 0;
|
||||
tset.tiles[i].frame_swap_time = 0;
|
||||
tset.tiles[i].frame_start_time = 0;
|
||||
}
|
||||
|
||||
int tset_id = rc_tileset.size();
|
||||
|
||||
if(rc_deleted_tileset.size() > 0)
|
||||
{
|
||||
tset_id = rc_deleted_tileset[0];
|
||||
rc_deleted_tileset.erase(rc_deleted_tileset.begin());
|
||||
rc_tileset[tset_id] = tset;
|
||||
}
|
||||
else
|
||||
rc_tileset.push_back(tset);
|
||||
|
||||
return tset_id;
|
||||
}
|
||||
|
||||
void rc_setTileAnimationLength(int tileset, int base_tile, int num_frames)
|
||||
{
|
||||
if(tileset < 0 || tileset >= rc_tileset.size())
|
||||
return;
|
||||
|
||||
if(!rc_tileset[tileset].active)
|
||||
return;
|
||||
|
||||
if(base_tile < 0 || base_tile >= rc_tileset[tileset].tiles.size())
|
||||
return;
|
||||
|
||||
rc_tileset[tileset].tiles[base_tile].frames.resize(num_frames);
|
||||
rc_tileset[tileset].tiles[base_tile].num_frames = num_frames;
|
||||
}
|
||||
|
||||
int rc_getTileAnimationLength(int tileset, int base_tile)
|
||||
{
|
||||
if(tileset < 0 || tileset >= rc_tileset.size())
|
||||
return 0;
|
||||
|
||||
if(!rc_tileset[tileset].active)
|
||||
return 0;
|
||||
|
||||
if(base_tile < 0 || base_tile >= rc_tileset[tileset].tiles.size())
|
||||
return 0;
|
||||
|
||||
return rc_tileset[tileset].tiles[base_tile].num_frames;
|
||||
}
|
||||
|
||||
void rc_setTileAnimationFrame(int tileset, int base_tile, int anim_frame, int tile_frame)
|
||||
{
|
||||
if(tileset < 0 || tileset >= rc_tileset.size())
|
||||
return;
|
||||
|
||||
if(!rc_tileset[tileset].active)
|
||||
return;
|
||||
|
||||
if(base_tile < 0 || base_tile >= rc_tileset[tileset].tiles.size())
|
||||
return;
|
||||
|
||||
rc_tileset[tileset].tiles[base_tile].frames[anim_frame] = tile_frame;
|
||||
}
|
||||
|
||||
int rc_getTileAnimationFrame(int tileset, int base_tile, int anim_frame)
|
||||
{
|
||||
if(tileset < 0 || tileset >= rc_tileset.size())
|
||||
return -1;
|
||||
|
||||
if(!rc_tileset[tileset].active)
|
||||
return -1;
|
||||
|
||||
if(base_tile < 0 || base_tile >= rc_tileset[tileset].tiles.size())
|
||||
return -1;
|
||||
|
||||
return rc_tileset[tileset].tiles[base_tile].frames[anim_frame];
|
||||
}
|
||||
|
||||
|
||||
void rc_setTileAnimationSpeed(int tileset, int base_tile, double speed)
|
||||
{
|
||||
if(tileset < 0 || tileset >= rc_tileset.size())
|
||||
return;
|
||||
|
||||
if(!rc_tileset[tileset].active)
|
||||
return;
|
||||
|
||||
if(base_tile < 0 || base_tile >= rc_tileset[tileset].tiles.size())
|
||||
return;
|
||||
|
||||
rc_tileset[tileset].tiles[base_tile].fps = speed;
|
||||
rc_tileset[tileset].tiles[base_tile].frame_swap_time = 1000/speed;
|
||||
}
|
||||
|
||||
double rc_getTileAnimationSpeed(int tileset, int base_tile)
|
||||
{
|
||||
if(tileset < 0 || tileset >= rc_tileset.size())
|
||||
return 0;
|
||||
|
||||
if(!rc_tileset[tileset].active)
|
||||
return 0;
|
||||
|
||||
if(base_tile < 0 || base_tile >= rc_tileset[tileset].tiles.size())
|
||||
return 0;
|
||||
|
||||
return rc_tileset[tileset].tiles[base_tile].fps;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------TILEMAP-----------------------------------------------
|
||||
int rc_createTileMap(int tileset, int widthInTiles, int heightInTiles)
|
||||
{
|
||||
if(tileset < 0 || tileset >= rc_tileset.size())
|
||||
return -1;
|
||||
|
||||
if(!rc_tileset[tileset].active)
|
||||
return -1;
|
||||
|
||||
rc_tilemap_obj tilemap;
|
||||
|
||||
tilemap.active = true;
|
||||
tilemap.texture = NULL;
|
||||
tilemap.tileset = tileset;
|
||||
|
||||
tilemap.num_tiles_across = widthInTiles;
|
||||
tilemap.num_tiles_down = heightInTiles;
|
||||
|
||||
tilemap.rows.resize(heightInTiles);
|
||||
for(int i = 0; i < tilemap.rows.size(); i++)
|
||||
{
|
||||
tilemap.rows[i].tile.resize(widthInTiles);
|
||||
}
|
||||
|
||||
int tm_id = rc_tilemap.size();
|
||||
|
||||
if(rc_deleted_tilemap.size() > 0)
|
||||
{
|
||||
tm_id = rc_deleted_tilemap[0];
|
||||
rc_deleted_tilemap.erase(rc_deleted_tilemap.begin());
|
||||
rc_tilemap[tm_id] = tilemap;
|
||||
}
|
||||
else
|
||||
rc_tilemap.push_back(tilemap);
|
||||
|
||||
return tm_id;
|
||||
}
|
||||
|
||||
void rc_setTileMapSize(int tilemap, int widthInTiles, int heightInTiles)
|
||||
{
|
||||
if(tilemap < 0 || tilemap >= rc_tilemap.size())
|
||||
return;
|
||||
|
||||
if(!rc_tilemap[tilemap].active)
|
||||
return;
|
||||
|
||||
rc_tilemap[tilemap].num_tiles_across = widthInTiles;
|
||||
rc_tilemap[tilemap].num_tiles_down = heightInTiles;
|
||||
|
||||
rc_tilemap[tilemap].rows.resize(heightInTiles);
|
||||
for(int i = 0; i < rc_tilemap[tilemap].rows.size(); i++)
|
||||
{
|
||||
rc_tilemap[tilemap].rows[i].tile.resize(widthInTiles);
|
||||
}
|
||||
}
|
||||
|
||||
void rc_getTileMapSize(int tilemap, double* widthInTiles, double* heightInTiles)
|
||||
{
|
||||
if(tilemap < 0 || tilemap >= rc_tilemap.size())
|
||||
return;
|
||||
|
||||
if(!rc_tilemap[tilemap].active)
|
||||
return;
|
||||
|
||||
*widthInTiles = rc_tilemap[tilemap].num_tiles_across;
|
||||
*heightInTiles = rc_tilemap[tilemap].num_tiles_down;
|
||||
}
|
||||
|
||||
void rc_setTile(int tilemap, int tile, int x, int y)
|
||||
{
|
||||
if(tilemap < 0 || tilemap >= rc_tilemap.size())
|
||||
return;
|
||||
|
||||
if(!rc_tilemap[tilemap].active)
|
||||
return;
|
||||
|
||||
int tileset = rc_tilemap[tilemap].tileset;
|
||||
|
||||
//if tilemap exists, then its safe to assume tileset is in range since tilemap can't be created if its not
|
||||
if(!rc_tileset[tileset].active)
|
||||
return;
|
||||
|
||||
int num_tset_tiles = rc_tileset[tileset].tiles.size();
|
||||
|
||||
if(tile < 0 || tile >= num_tset_tiles)
|
||||
return;
|
||||
|
||||
if( (x < 0 || x >= rc_tilemap[tilemap].num_tiles_across) || (y < 0 || y >= rc_tilemap[tilemap].num_tiles_down) )
|
||||
return;
|
||||
|
||||
rc_tilemap[tilemap].rows[y].tile[x] = tile;
|
||||
}
|
||||
|
||||
int rc_getTile(int tilemap, int x, int y)
|
||||
{
|
||||
if(tilemap < 0 || tilemap >= rc_tilemap.size())
|
||||
return -1;
|
||||
|
||||
if(!rc_tilemap[tilemap].active)
|
||||
return -1;
|
||||
|
||||
if( (x < 0 || x >= rc_tilemap[tilemap].num_tiles_across) || (y < 0 || y >= rc_tilemap[tilemap].num_tiles_down) )
|
||||
return -1;
|
||||
|
||||
return rc_tilemap[tilemap].rows[y].tile[x];
|
||||
}
|
||||
|
||||
void rc_fillTile(int tilemap, int tile, int x, int y, int widthInTiles, int heightInTiles)
|
||||
{
|
||||
if(tilemap < 0 || tilemap >= rc_tilemap.size())
|
||||
return;
|
||||
|
||||
if(!rc_tilemap[tilemap].active)
|
||||
return;
|
||||
|
||||
int tileset = rc_tilemap[tilemap].tileset;
|
||||
|
||||
//if tilemap exists, then its safe to assume tileset is in range since tilemap can't be created if its not
|
||||
if(!rc_tileset[tileset].active)
|
||||
return;
|
||||
|
||||
int num_tset_tiles = rc_tileset[tileset].tiles.size();
|
||||
|
||||
if(tile < 0 || tile >= num_tset_tiles)
|
||||
return;
|
||||
|
||||
if( (x < 0 || x >= rc_tilemap[tilemap].num_tiles_across) || (y < 0 || y >= rc_tilemap[tilemap].num_tiles_down) )
|
||||
return;
|
||||
|
||||
if( ( (x+widthInTiles) < 0 || (x+widthInTiles) > rc_tilemap[tilemap].num_tiles_across) || ( (y+heightInTiles) < 0 || (y+heightInTiles) > rc_tilemap[tilemap].num_tiles_down) )
|
||||
return;
|
||||
|
||||
for(int iy = 0; iy < heightInTiles; iy++)
|
||||
for(int ix = 0; ix < widthInTiles; ix++)
|
||||
rc_tilemap[tilemap].rows[y+iy].tile[x+ix] = tile;
|
||||
}
|
||||
|
||||
void getTileInTileset(int tileset, int tile, int* x, int* y)
|
||||
{
|
||||
int img_w = rc_image[ rc_tileset[tileset].img_id ].image->getSize().Width;
|
||||
int img_h = rc_image[ rc_tileset[tileset].img_id ].image->getSize().Height;
|
||||
int tile_w = rc_tileset[tileset].tile_width;
|
||||
int tile_h = rc_tileset[tileset].tile_height;
|
||||
int widthInTiles = img_w / tile_w;
|
||||
|
||||
*x = (tile%widthInTiles) * tile_w;
|
||||
*y = (tile/widthInTiles) * tile_h;
|
||||
}
|
||||
|
||||
int getNumTilesInTileset(int tileset)
|
||||
{
|
||||
int img_w = rc_image[ rc_tileset[tileset].img_id ].image->getSize().Width;
|
||||
int img_h = rc_image[ rc_tileset[tileset].img_id ].image->getSize().Height;
|
||||
int tile_w = rc_tileset[tileset].tile_width;
|
||||
int tile_h = rc_tileset[tileset].tile_height;
|
||||
int widthInTiles = img_w / tile_w;
|
||||
int heightInTiles = img_h / tile_h;
|
||||
|
||||
return (widthInTiles*heightInTiles);
|
||||
}
|
||||
|
||||
void updateTileset(int tileset)
|
||||
{
|
||||
Uint32 current_time_ms = SDL_GetTicks();
|
||||
for(int i = 0; i < rc_tileset[tileset].tiles.size(); i++)
|
||||
{
|
||||
if( (current_time_ms-rc_tileset[tileset].tiles[i].frame_start_time) >= rc_tileset[tileset].tiles[i].frame_swap_time )
|
||||
{
|
||||
rc_tileset[tileset].tiles[i].current_frame++;
|
||||
if(rc_tileset[tileset].tiles[i].current_frame >= rc_tileset[tileset].tiles[i].num_frames)
|
||||
rc_tileset[tileset].tiles[i].current_frame = 0;
|
||||
|
||||
rc_tileset[tileset].tiles[i].frame_start_time = current_time_ms;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rc_drawTileMap(int tilemap, int x, int y, int w, int h, int offset_x, int offset_y)
|
||||
{
|
||||
if(tilemap < 0 || tilemap >= rc_tilemap.size())
|
||||
return;
|
||||
|
||||
if(!rc_tilemap[tilemap].active)
|
||||
return;
|
||||
|
||||
if(rc_active_canvas < 0 || rc_active_canvas >= rc_canvas.size())
|
||||
return;
|
||||
|
||||
if(!rc_canvas[rc_active_canvas].type == RC_CANVAS_TYPE_2D)
|
||||
return;
|
||||
|
||||
if(!rc_canvas[rc_active_canvas].texture)
|
||||
return;
|
||||
|
||||
rc_tilemap[tilemap].texture = VideoDriver->addRenderTargetTexture(irr::core::dimension2d<u32>(w,h), "rt", ECF_A8R8G8B8);
|
||||
VideoDriver->setRenderTarget(rc_tilemap[tilemap].texture, true, true, irr::video::SColor(0,0,0,0));
|
||||
|
||||
|
||||
int tileset = rc_tilemap[tilemap].tileset;
|
||||
|
||||
updateTileset(tileset);
|
||||
|
||||
int vp_widthInTiles = w/rc_tileset[tileset].tile_width;
|
||||
int vp_heightInTiles = h/rc_tileset[tileset].tile_height;
|
||||
|
||||
int tset_img_id = rc_tileset[tileset].img_id;
|
||||
int src_w = rc_tileset[tileset].tile_width;
|
||||
int src_h = rc_tileset[tileset].tile_height;
|
||||
|
||||
int tile_offset_x = offset_x / src_w;
|
||||
int tile_offset_y = offset_y / src_h;
|
||||
|
||||
int screen_offset_x = 0 - (offset_x % src_w);
|
||||
int screen_offset_y = 0 - (offset_y % src_h);
|
||||
|
||||
int num_tiles_in_tset = getNumTilesInTileset(tileset);
|
||||
|
||||
for(int iy = 0; iy < vp_heightInTiles+1; iy++)
|
||||
{
|
||||
for(int ix = 0; ix < vp_widthInTiles+1; ix++)
|
||||
{
|
||||
int current_frame = 0; //TODO: ADD TIMING
|
||||
int map_x = tile_offset_x + ix;
|
||||
int map_y = tile_offset_y + iy;
|
||||
|
||||
if(map_x < 0 || map_x >= rc_tilemap[tilemap].num_tiles_across || map_y < 0 || map_y >= rc_tilemap[tilemap].num_tiles_down)
|
||||
continue;
|
||||
|
||||
int tile = rc_tilemap[tilemap].rows[map_y].tile[map_x];
|
||||
|
||||
if(tile < 0 || tile >= num_tiles_in_tset)
|
||||
continue;
|
||||
|
||||
current_frame = rc_tileset[tileset].tiles[tile].current_frame;
|
||||
tile = rc_tileset[tileset].tiles[tile].frames[current_frame];
|
||||
|
||||
if(tile < 0 || tile >= num_tiles_in_tset)
|
||||
continue;
|
||||
|
||||
int src_x = 0;
|
||||
int src_y = 0;
|
||||
getTileInTileset(tileset, tile, &src_x, &src_y);
|
||||
irr::core::rect<irr::s32> sourceRect( irr::core::vector2d<irr::s32>(src_x, src_y), irr::core::dimension2d<irr::s32>(src_w, src_h));
|
||||
|
||||
irr::video::SColor color(rc_image[tset_img_id].alpha,
|
||||
rc_image[tset_img_id].color_mod.getRed(),
|
||||
rc_image[tset_img_id].color_mod.getGreen(),
|
||||
rc_image[tset_img_id].color_mod.getBlue());
|
||||
|
||||
int dst_x = screen_offset_x + (ix*src_w);
|
||||
int dst_y = screen_offset_y + (iy*src_h);
|
||||
irr::core::rect<irr::s32> dest( irr::core::vector2d<irr::s32>(dst_x, dst_y), irr::core::dimension2d<irr::s32>(src_w, src_h));
|
||||
|
||||
|
||||
VideoDriver->draw2DImage(rc_image[tset_img_id].image, dest, sourceRect, 0, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
VideoDriver->setRenderTarget(rc_canvas[rc_active_canvas].texture, false, false);
|
||||
|
||||
irr::core::rect<irr::s32> sourceRect( irr::core::vector2d<irr::s32>(0, 0), irr::core::dimension2d<irr::s32>(w, h));
|
||||
irr::core::rect<irr::s32> dest( irr::core::vector2d<irr::s32>(x, y), irr::core::dimension2d<irr::s32>(w, h));
|
||||
|
||||
VideoDriver->draw2DImage(rc_tilemap[tilemap].texture, dest, sourceRect, 0, 0, false);
|
||||
VideoDriver->removeTexture(rc_tilemap[tilemap].texture);
|
||||
rc_tilemap[tilemap].texture = NULL;
|
||||
//draw2DImage(VideoDriver, rc_tilemap[tilemap].texture, src, pos,)
|
||||
}
|
||||
|
||||
|
||||
#endif // RC_TILELIB_H_INCLUDED
|
||||
57
rcbasic_runtime/rc_tilemap.h
Normal file
57
rcbasic_runtime/rc_tilemap.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef RC_TILEMAP_H_INCLUDED
|
||||
#define RC_TILEMAP_H_INCLUDED
|
||||
|
||||
#include <irrlicht.h>
|
||||
#include <vector>
|
||||
|
||||
struct rc_tile_obj
|
||||
{
|
||||
int id;
|
||||
|
||||
double fps;
|
||||
int num_frames;
|
||||
int current_frame;
|
||||
std::vector<int> frames;
|
||||
|
||||
Uint32 frame_start_time;
|
||||
Uint32 frame_swap_time;
|
||||
};
|
||||
|
||||
struct rc_tileset_obj
|
||||
{
|
||||
bool active;
|
||||
|
||||
int img_id;
|
||||
|
||||
int tile_width;
|
||||
int tile_height;
|
||||
|
||||
std::vector<rc_tile_obj> tiles;
|
||||
};
|
||||
|
||||
struct rc_tilemap_row_obj
|
||||
{
|
||||
std::vector<int> tile;
|
||||
};
|
||||
|
||||
struct rc_tilemap_obj
|
||||
{
|
||||
bool active;
|
||||
|
||||
int tileset;
|
||||
irr::video::ITexture* texture;
|
||||
|
||||
int num_tiles_across;
|
||||
int num_tiles_down;
|
||||
|
||||
std::vector<rc_tilemap_row_obj> rows;
|
||||
};
|
||||
|
||||
std::vector<rc_tileset_obj> rc_tileset;
|
||||
std::vector<rc_tilemap_obj> rc_tilemap;
|
||||
|
||||
std::vector<int> rc_deleted_tileset;
|
||||
std::vector<int> rc_deleted_tilemap;
|
||||
|
||||
|
||||
#endif // RC_TILEMAP_H_INCLUDED
|
||||
Reference in New Issue
Block a user