mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-06 22:08:19 +03:00
== Handles As a general pattern, these libraries have an interface based on integer handles allocated by Open() and released by Close(); in the AliceSoft's implementation, handles are pointers to internal objects. Note that: * 0 is used to represent an invalid handle, and * Small numbers cannot be handles. For example, Mamanyonyo has code that treats an integer as a CG number if it is less than 10000, and as a surface handle otherwise. In this patch, handles are generated using id_pool.h functions. In order to achieve the above, the interface is extended so that the minimum ID value can be specified (the `base` parameter of id_pool_init()). == Graphics System Surface objects (implemented in vmSurface.[ch]) plays a central role in Mamanyonyo's graphics system, and the sprite system (vmSprite.c) is implemented on top of it. vmSprite.c uses scene.h functions. == vmChrLoader and vmMapLoader Since Mamanyonyo's character data format is the same as Widenyo's, the ChrLoader code has been refactored and used from vmChrLoader.c. On the other hand, MapLoader and vmMapLoader do not share code because the map file format is different from Widenyo.
86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
/* Copyright (C) 2024 kichikuou <KichikuouChrome@gmail.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, see <http://gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "system4.h"
|
|
#include "system4/cg.h"
|
|
|
|
#include "asset_manager.h"
|
|
#include "gfx/gfx.h"
|
|
#include "hll.h"
|
|
#include "vmSurface.h"
|
|
|
|
HLL_QUIET_UNIMPLEMENTED( , void, vmCG, New, void);
|
|
//int vmCG_Release(void);
|
|
HLL_WARN_UNIMPLEMENTED( , void, vmCG, SetType, int type);
|
|
//int vmCG_EnumHandle(void);
|
|
|
|
static int vmCG_Exist(int num)
|
|
{
|
|
return asset_exists(ASSET_CG, num);
|
|
}
|
|
|
|
static int vmCG_Load(int num)
|
|
{
|
|
struct cg *cg = asset_cg_load(num);
|
|
if (!cg)
|
|
return 0;
|
|
struct vm_surface *sf = vm_surface_create(cg->metrics.w, cg->metrics.h);
|
|
gfx_init_texture_with_cg(&sf->texture, cg);
|
|
sf->has_pixel = cg->metrics.has_pixel;
|
|
sf->has_alpha = cg->metrics.has_alpha;
|
|
sf->cg_no = num;
|
|
cg_free(cg);
|
|
return sf->no;
|
|
}
|
|
|
|
static void vmCG_Unload(int surface)
|
|
{
|
|
vm_surface_delete(surface);
|
|
}
|
|
|
|
static int vmCG_Trans(int surface, int x, int y, int num)
|
|
{
|
|
struct vm_surface *sf = vm_surface_get(surface);
|
|
if (!sf)
|
|
return 0;
|
|
|
|
struct cg *cg = asset_cg_load(num);
|
|
if (!cg)
|
|
return 0;
|
|
|
|
Texture src;
|
|
gfx_init_texture_with_cg(&src, cg);
|
|
cg_free(cg);
|
|
|
|
if (sf->has_alpha)
|
|
gfx_copy_with_alpha_map(&sf->texture, x, y, &src, 0, 0, src.w, src.h);
|
|
else
|
|
gfx_blend_amap(&sf->texture, x, y, &src, 0, 0, src.w, src.h);
|
|
gfx_delete_texture(&src);
|
|
return 1;
|
|
}
|
|
|
|
HLL_LIBRARY(vmCG,
|
|
HLL_EXPORT(New, vmCG_New),
|
|
HLL_TODO_EXPORT(Release, vmCG_Release),
|
|
HLL_EXPORT(SetType, vmCG_SetType),
|
|
HLL_TODO_EXPORT(EnumHandle, vmCG_EnumHandle),
|
|
HLL_EXPORT(Exist, vmCG_Exist),
|
|
HLL_EXPORT(Load, vmCG_Load),
|
|
HLL_EXPORT(Unload, vmCG_Unload),
|
|
HLL_EXPORT(Trans, vmCG_Trans)
|
|
);
|